From bcec31a2a79f185f4890febe95732d46e40917a3 Mon Sep 17 00:00:00 2001 From: Cory Slep Date: Mon, 12 Feb 2018 21:19:35 +0100 Subject: [PATCH] Internalize interfaces that should not be public. --- pub/fed.go | 102 ---------------------------------------------- pub/interfaces.go | 14 +++---- pub/internal.go | 32 +++++++-------- pub/resolvers.go | 6 +-- 4 files changed, 24 insertions(+), 130 deletions(-) diff --git a/pub/fed.go b/pub/fed.go index a2d935f..0eea9f3 100644 --- a/pub/fed.go +++ b/pub/fed.go @@ -18,108 +18,6 @@ var ( ErrTypeRequired = errors.New("type property required") ) -// Object is the interface for ActivityPub compliant ActivityStream types. -// -// ActivityPub obects must have 'id' and 'type' properties to be spec compliant. -// This library enforces the "MUST" requirement and purposefully does NOT -// support transient objects. -// -// Furthermore, the spec extends the Object ActivityStream type to also contain -// the 'source' property, whose value appears to be an Object with only -// 'content' and 'mediaType' properties being semantically useful. -// -// TODO: Possibly delete this interface -type Object interface { - GetId() (streams.Resolution, url.URL) - SetId(url.URL) - HasId() streams.Presence - LenType() int - GetType(int) (streams.Resolution, string) - AddType(interface{}) - RemoveType(int) - ResolveSource(*streams.Resolver) (streams.Resolution, error) - HasSource() streams.Presence - SetSource(vocab.ObjectType) - Serialize() (m map[string]interface{}, err error) -} - -var _ Object = &streams.Object{} - -// Actor is the interface for ActivityPub compliant ActivityStream types. -// -// ActivityPub actors must have a valid unique IRI as the 'id' property in -// addition to the 'type' property. Furthermore, actors must have the 'inbox' -// and 'outbox' properties to be considered actors. There are more suggested -// properties by the spec, which we include here. -// -// TODO: Possibly delete this interface -type Actor interface { - GetId() (streams.Resolution, url.URL) - SetId(url.URL) - LenType() int - GetType(int) (streams.Resolution, string) - AddType(interface{}) - RemoveType(int) - GetInbox() (streams.Resolution, url.URL) - HasInbox() streams.Presence - SetInbox(url.URL) - GetOutbox() (streams.Resolution, url.URL) - HasOutbox() streams.Presence - SetOutbox(url.URL) - GetFollowing() (streams.Resolution, url.URL) - HasFollowing() streams.Presence - SetFollowing(url.URL) - GetFollowers() (streams.Resolution, url.URL) - HasFollowers() streams.Presence - SetFollowers(url.URL) - GetLiked() (streams.Resolution, url.URL) - HasLiked() streams.Presence - SetLiked(url.URL) - LenStreams() int - GetStreams(int) (streams.Resolution, url.URL) - AddStreams(vocab.CollectionType) - RemoveStreams(int) - GetPreferredUsername() (streams.Resolution, string) - HasPreferredUsername() streams.Presence - SetPreferredUsername(string) - PreferredUsernameLanguages() []string - GetPreferredUsernameForLanguage(string) string - SetPreferredUsernameForLanguage(string, string) - ResolveEndpoints(streams.Resolver) (streams.Resolution, error) - HasEndpoints() streams.Presence - SetEndpoints(vocab.ObjectType) - Serialize() (m map[string]interface{}, err error) -} - -var _ Object = &streams.Object{} - -// Endpoint is a logical grouping of specific properties within the ActivityPub -// specification. -// -// TODO: Possibly delete this interface -type Endpoint interface { - GetProxyUrl() (streams.Resolution, url.URL) - HasProxyUrl() streams.Presence - SetProxyUrl(url.URL) - GetOauthAuthorizationEndpoint() (streams.Resolution, url.URL) - HasOauthAuthorizationEndpoint() streams.Presence - SetOauthAuthorizationEndpoint(url.URL) - GetOauthTokenEndpoint() (streams.Resolution, url.URL) - HasOauthTokenEndpoint() streams.Presence - SetOauthTokenEndpoint(url.URL) - GetProvideClientKey() (streams.Resolution, url.URL) - HasProvideClientKey() streams.Presence - SetProvideClientKey(url.URL) - GetSignClientKey() (streams.Resolution, url.URL) - HasSignClientKey() streams.Presence - SetSignClientKey(url.URL) - GetSharedInbox() (streams.Resolution, url.URL) - HasSharedInbox() streams.Presence - SetSharedInbox(url.URL) -} - -var _ Endpoint = &streams.Object{} - // TODO: Helper http Handler for serving ActivityStream objects // TODO: Helper http Handler for serving Tombstone objects // TODO: Helper http Handler for serving deleted objects diff --git a/pub/interfaces.go b/pub/interfaces.go index d89d3e6..fa31922 100644 --- a/pub/interfaces.go +++ b/pub/interfaces.go @@ -17,11 +17,9 @@ import ( // response to send to the requester. type HandlerFunc func(http.ResponseWriter, *http.Request) (bool, error) -// ActorObject is an object that has "actor" or "attributedTo" properties, +// actorObject is an object that has "actor" or "attributedTo" properties, // representing the author or originator of the object. -// -// TODO: Convert this to be an internal interface. -type ActorObject interface { +type actorObject interface { HasInbox() (ok bool) GetInbox() (v url.URL) AttributedToLen() (l int) @@ -40,12 +38,10 @@ type ActorObject interface { GetActorIRI(index int) (v url.URL) } -// DeliverableObject is an object that is able to be sent to recipients via the +// deliverableObject is an object that is able to be sent to recipients via the // "to", "bto", "cc", "bcc", and "audience" objects and/or links and/or IRIs. -// -// TODO: Convert this to be an internal interface. -type DeliverableObject interface { - ActorObject +type deliverableObject interface { + actorObject ToLen() (l int) IsToObject(index int) (ok bool) GetToObject(index int) (v vocab.ObjectType) diff --git a/pub/internal.go b/pub/internal.go index 9087e35..898fb22 100644 --- a/pub/internal.go +++ b/pub/internal.go @@ -168,10 +168,10 @@ func (f *federator) wrapInCreate(o vocab.ObjectType, actor url.URL) *vocab.Creat // TODO: (Section 7) HTTP caching mechanisms [RFC7234] SHOULD be respected when appropriate, both when receiving responses from other servers as well as sending responses to other servers. -// prepare takes a DeliverableObject and returns a list of the proper recipient -// target URIs. Additionally, the DeliverableObject will have any hidden +// prepare takes a deliverableObject and returns a list of the proper recipient +// target URIs. Additionally, the deliverableObject will have any hidden // hidden recipients ("bto" and "bcc") stripped from it. -func (c *federator) prepare(o DeliverableObject) ([]url.URL, error) { +func (c *federator) prepare(o deliverableObject) ([]url.URL, error) { // Get inboxes of recipients var r []url.URL r = append(r, getToIRIs(o)...) @@ -207,13 +207,13 @@ func (c *federator) prepare(o DeliverableObject) ([]url.URL, error) { } // resolveInboxes takes a list of Actor id URIs and returns them as concrete -// instances of ActorObject. It applies recursively when it encounters a target +// instances of actorObject. It applies recursively when it encounters a target // that is a Collection or OrderedCollection. -func (c *federator) resolveInboxes(r []url.URL, depth int, max int) ([]ActorObject, error) { +func (c *federator) resolveInboxes(r []url.URL, depth int, max int) ([]actorObject, error) { if depth >= max { return nil, nil } - a := make([]ActorObject, 0, len(r)) + a := make([]actorObject, 0, len(r)) for _, u := range r { // Do not retry here -- if a dereference fails, then fail the // entire delivery. @@ -225,7 +225,7 @@ func (c *federator) resolveInboxes(r []url.URL, depth int, max int) ([]ActorObje if err = json.Unmarshal(resp, &m); err != nil { return nil, err } - var actor ActorObject + var actor actorObject var co *streams.Collection var oc *streams.OrderedCollection var cp *streams.CollectionPage @@ -289,7 +289,7 @@ func (c *federator) resolveInboxes(r []url.URL, depth int, max int) ([]ActorObje } // getInboxes extracts the 'inbox' IRIs from actors. -func getInboxes(a []ActorObject) []url.URL { +func getInboxes(a []actorObject) []url.URL { var u []url.URL for _, actor := range a { if actor.HasInbox() { @@ -301,7 +301,7 @@ func getInboxes(a []ActorObject) []url.URL { // getActorAttributedToURI attempts to find the URIs for the "actor" and // "attributedTo" originators on the object. -func getActorsAttributedToURI(a ActorObject) []url.URL { +func getActorsAttributedToURI(a actorObject) []url.URL { var u []url.URL for i := 0; i < a.AttributedToLen(); i++ { if a.IsAttributedToObject(i) { @@ -336,10 +336,10 @@ func getActorsAttributedToURI(a ActorObject) []url.URL { return u } -// stripHiddenRecipients removes "bto" and "bcc" from the DeliverableObject. +// stripHiddenRecipients removes "bto" and "bcc" from the deliverableObject. // Note that this requirement of the specification is under "Section 6: Client // to Server Interactions", the Social API, and not the Federative API. -func stripHiddenRecipients(o DeliverableObject) { +func stripHiddenRecipients(o deliverableObject) { for o.BtoLen() > 0 { if o.IsBtoObject(0) { o.RemoveBtoObject(0) @@ -432,7 +432,7 @@ func filterURLs(u []url.URL, fn func(s string) bool) []url.URL { return u } -func getToIRIs(o DeliverableObject) []url.URL { +func getToIRIs(o deliverableObject) []url.URL { var r []url.URL for i := 0; i < o.ToLen(); i++ { if o.IsToObject(i) { @@ -452,7 +452,7 @@ func getToIRIs(o DeliverableObject) []url.URL { return r } -func getBToIRIs(o DeliverableObject) []url.URL { +func getBToIRIs(o deliverableObject) []url.URL { var r []url.URL for i := 0; i < o.BtoLen(); i++ { if o.IsBtoObject(i) { @@ -472,7 +472,7 @@ func getBToIRIs(o DeliverableObject) []url.URL { return r } -func getCcIRIs(o DeliverableObject) []url.URL { +func getCcIRIs(o deliverableObject) []url.URL { var r []url.URL for i := 0; i < o.CcLen(); i++ { if o.IsCcObject(i) { @@ -492,7 +492,7 @@ func getCcIRIs(o DeliverableObject) []url.URL { return r } -func getBccIRIs(o DeliverableObject) []url.URL { +func getBccIRIs(o deliverableObject) []url.URL { var r []url.URL for i := 0; i < o.BccLen(); i++ { if o.IsBccObject(i) { @@ -512,7 +512,7 @@ func getBccIRIs(o DeliverableObject) []url.URL { return r } -func getAudienceIRIs(o DeliverableObject) []url.URL { +func getAudienceIRIs(o deliverableObject) []url.URL { var r []url.URL for i := 0; i < o.AudienceLen(); i++ { if o.IsAudienceObject(i) { diff --git a/pub/resolvers.go b/pub/resolvers.go index 7863030..2cbdbc4 100644 --- a/pub/resolvers.go +++ b/pub/resolvers.go @@ -7,10 +7,10 @@ import ( "net/url" ) -func toActorResolver(a *ActorObject) *streams.Resolver { +func toActorResolver(a *actorObject) *streams.Resolver { return &streams.Resolver{ AnyObjectCallback: func(i vocab.ObjectType) error { - if o, ok := i.(ActorObject); ok { + if o, ok := i.(actorObject); ok { *a = o } return nil @@ -18,7 +18,7 @@ func toActorResolver(a *ActorObject) *streams.Resolver { } } -func toActorCollectionResolver(a *ActorObject, c **streams.Collection, oc **streams.OrderedCollection, cp **streams.CollectionPage, ocp **streams.OrderedCollectionPage) *streams.Resolver { +func toActorCollectionResolver(a *actorObject, c **streams.Collection, oc **streams.OrderedCollection, cp **streams.CollectionPage, ocp **streams.OrderedCollectionPage) *streams.Resolver { r := toActorResolver(a) r.CollectionCallback = func(i *streams.Collection) error { *c = i