Add instance nodeinfo

master
Matt Baer 2019-10-28 23:14:36 -04:00
parent 7eb1d2e2b2
commit 898c97700f
2 changed files with 57 additions and 0 deletions

View File

@ -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)

52
nodeinfo.go Normal file
View File

@ -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
}