Improve performance

This commit is contained in:
Melroy van den Berg 2025-04-25 01:07:45 +02:00
parent d85cf4bd11
commit 8e5a08ab5f
No known key found for this signature in database
GPG key ID: 71D11FF23454B9D7

View file

@ -3,7 +3,6 @@ package resolver
import ( import (
"crypto/rand" "crypto/rand"
"crypto/rsa" "crypto/rsa"
"encoding/json"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
@ -274,33 +273,19 @@ func (r *Resolver) fetchNodeInfo(domain string) ([]byte, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("error reading nodeinfo discovery: %v", err) return nil, fmt.Errorf("error reading nodeinfo discovery: %v", err)
} }
var discovery struct {
Links []struct {
Rel string `json:"rel"`
Href string `json:"href"`
} `json:"links"`
}
if err := json.Unmarshal(body, &discovery); err != nil {
return nil, fmt.Errorf("error parsing nodeinfo discovery: %v", err)
}
var nodeinfoHref string var nodeinfoHref string
for _, link := range discovery.Links { result := gjson.GetBytes(body, `links.#(rel%"*/schema/2.1").href`)
if strings.HasSuffix(link.Rel, "/schema/2.1") { if !result.Exists() {
nodeinfoHref = link.Href result = gjson.GetBytes(body, `links.#(rel%"*/schema/2.0").href`)
break
}
}
if nodeinfoHref == "" {
for _, link := range discovery.Links {
if strings.HasSuffix(link.Rel, "/schema/2.0") {
nodeinfoHref = link.Href
break
}
} }
if result.Exists() {
nodeinfoHref = result.String()
} }
if nodeinfoHref == "" { if nodeinfoHref == "" {
return nil, fmt.Errorf("no nodeinfo schema 2.1 or 2.0 found") return nil, fmt.Errorf("no nodeinfo schema 2.1 or 2.0 found")
} }
fmt.Printf("Fetching nodeinfo from: %s\n", nodeinfoHref) fmt.Printf("Fetching nodeinfo from: %s\n", nodeinfoHref)
resp2, err := r.client.Get(nodeinfoHref) resp2, err := r.client.Get(nodeinfoHref)
if err != nil { if err != nil {