diff --git a/http.go b/http.go index 7fd2220..1126343 100644 --- a/http.go +++ b/http.go @@ -9,6 +9,7 @@ import ( "github.com/gologme/log" "github.com/gorilla/mux" + "github.com/writefreely/go-nodeinfo" "encoding/json" ) @@ -332,6 +333,10 @@ func Serve(actors map[string]Actor) { // Add the handlers to a HTTP server gorilla := mux.NewRouter() + niCfg := nodeInfoConfig(baseURL) + ni := nodeinfo.NewService(*niCfg, nodeInfoResolver{len(actors)}) + gorilla.HandleFunc(nodeinfo.NodeInfoPath, http.HandlerFunc(ni.NodeInfoDiscover)) + gorilla.HandleFunc(niCfg.InfoURL, http.HandlerFunc(ni.NodeInfo)) gorilla.HandleFunc("/.well-known/webfinger", webfingerHandler) gorilla.HandleFunc("/{actor}/peers/{peers}", peersHandler) gorilla.HandleFunc("/{actor}/outbox", outboxHandler) diff --git a/nodeinfo.go b/nodeinfo.go new file mode 100644 index 0000000..e26dd2a --- /dev/null +++ b/nodeinfo.go @@ -0,0 +1,52 @@ +package activityserve + +import ( + "strings" + + "github.com/writefreely/go-nodeinfo" +) + +type nodeInfoResolver struct { + actors int +} + +func nodeInfoConfig(baseURL string) *nodeinfo.Config { + name := "Pherephone" + desc := "An ActivityPub repeater." + return &nodeinfo.Config{ + BaseURL: baseURL, + InfoURL: "/api/nodeinfo", + + Metadata: nodeinfo.Metadata{ + NodeName: name, + NodeDescription: desc, + Software: nodeinfo.SoftwareMeta{ + HomePage: "https://pherephone.org", + GitHub: "https://github.com/writeas/pherephone", + }, + }, + Protocols: []nodeinfo.NodeProtocol{ + nodeinfo.ProtocolActivityPub, + }, + Services: nodeinfo.Services{ + Inbound: []nodeinfo.NodeService{}, + Outbound: []nodeinfo.NodeService{}, + }, + Software: nodeinfo.SoftwareInfo{ + Name: strings.ToLower(libName), + Version: version, + }, + } +} + +func (r nodeInfoResolver) IsOpenRegistration() (bool, error) { + return false, nil +} + +func (r nodeInfoResolver) Usage() (nodeinfo.Usage, error) { + return nodeinfo.Usage{ + Users: nodeinfo.UsageUsers{ + Total: r.actors, + }, + }, nil +}