Live tracking bug fixes

This commit is contained in:
Farhan Khan 2023-07-14 02:42:07 +00:00
parent 4dde79f6e2
commit 91e607ae6c
Signed by untrusted user who does not match committer: farhan
GPG Key ID: 45FE45AD7E54F59B
3 changed files with 46 additions and 39 deletions

View File

@ -40,9 +40,11 @@ func StatusReport() {
mastodon := 0 mastodon := 0
pleroma := 0 pleroma := 0
misskey := 0
other := 0 other := 0
ri_mutex.Lock() ri_mutex.Lock()
for _, o := range runninginstances { for i, o := range runninginstances {
logDebug("Software ", o.Software, " Status: ", o.Status, " instance ", i)
if o.Status == 200 { if o.Status == 200 {
running = running + 1 running = running + 1
} else if o.Status == 607 { // Keepalive } else if o.Status == 607 { // Keepalive
@ -55,12 +57,14 @@ func StatusReport() {
mastodon = mastodon + 1 mastodon = mastodon + 1
} else if o.Software == "pleroma" && o.Status == 200 { } else if o.Software == "pleroma" && o.Status == 200 {
pleroma = pleroma + 1 pleroma = pleroma + 1
} else if o.Software == "misskey" && o.Status == 200 {
misskey = misskey + 1
} else if o.Status == 200 { } else if o.Status == 200 {
other = other + 1 other = other + 1
} }
} }
ri_mutex.Unlock() ri_mutex.Unlock()
logInfo("Running:", running, " Keepalive:", keepalive, " Unsupported:", unsupported, " M:", mastodon, ",P:", pleroma, ",O:", other) logInfo("Running:", running, " Keepalive:", keepalive, " Unsupported:", unsupported, " Ma:", mastodon, ",P:", pleroma, ",Mi:", misskey, ",O:", other)
} }
func main() { func main() {

View File

@ -4,12 +4,10 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"math/rand" "math/rand"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"strings"
"time" "time"
"gitlab.com/khanzf/fedilogue/shared" "gitlab.com/khanzf/fedilogue/shared"
@ -35,6 +33,7 @@ func DoTries(o *shared.RunningInstance, req *http.Request) (*http.Response, erro
} }
func BuildClient(endpoint string) http.Client { func BuildClient(endpoint string) http.Client {
logDebug("BuildClient for ", endpoint)
// Test: TestBuildClient, TestBuildClientProxy // Test: TestBuildClient, TestBuildClientProxy
/* The seemingly unused 'endpoint' variable is for proxying based on endpoint, ie for Tor */ /* The seemingly unused 'endpoint' variable is for proxying based on endpoint, ie for Tor */
tr := &http.Transport{ tr := &http.Transport{
@ -99,16 +98,18 @@ func UpdateRunner(endpoint string, o shared.RunningInstance) {
func GetInstanceInfo(endpoint string, o shared.RunningInstance) shared.RunningInstance { func GetInstanceInfo(endpoint string, o shared.RunningInstance) shared.RunningInstance {
/* Checking order /* Checking order
* Mastodon/Pleroma * Mastodon/Pleroma/Misskey
* Um..nothing else yet * Um..nothing else yet
*/ */
logDebug("GetInstanceInfo for ", endpoint)
var nodeinfo shared.NodeInfo var nodeinfo shared.NodeInfo
pleromastodon_nodeinfo_uri := "https://" + endpoint + "/nodeinfo/2.0.json" pleromastodon_nodeinfo_uri := "https://" + endpoint + "/nodeinfo/2.0.json"
req, _ := http.NewRequest("GET", pleromastodon_nodeinfo_uri, nil) // Checking Mastodon and Pleroma (with .json)
req.Header.Set("User-Agent", "Tusky") reqjson, _ := http.NewRequest("GET", pleromastodon_nodeinfo_uri, nil)
reqjson.Header.Set("User-Agent", "Tusky")
pleromastodon_api_resp, err := DoTries(&o, req) pleromastodon_api_resp, err := DoTries(&o, reqjson)
if err != nil { if err != nil {
o.Software = "Unsupported" o.Software = "Unsupported"
return o return o
@ -127,47 +128,38 @@ func GetInstanceInfo(endpoint string, o shared.RunningInstance) shared.RunningIn
} }
} }
// Check the front page // Checking for Misskey (without .json)
index_uri := "https://" + endpoint + "/" misskey_nodeinfo_uri := "https://" + endpoint + "/nodeinfo/2.0"
req, _ = http.NewRequest("GET", index_uri, nil) req, _ := http.NewRequest("GET", misskey_nodeinfo_uri, nil)
req.Header.Set("User-Agent", "Tusky") req.Header.Set("User-Agent", "Tusky")
resp_index, err := DoTries(&o, req)
o.LastRun = time.Now().Format(time.RFC3339)
if err != nil {
o.Status = shared.UNSUPPORTED_INSTANCE
o.Software = "Unsupported"
logWarn("Unable to connect to " + endpoint + ", giving up")
return o
}
defer resp_index.Body.Close()
indexbin, err := ioutil.ReadAll(resp_index.Body) misskey_api_resp, err := DoTries(&o, req)
if err != nil { if err != nil {
o.Status = shared.UNSUPPORTED_INSTANCE
o.Software = "Unsupported" o.Software = "Unsupported"
logWarn("Unable to read index of " + endpoint + ", giving up")
return o return o
}
indexstr := string(indexbin)
if strings.Contains(indexstr, "Pleroma") || strings.Contains(indexstr, "Soapbox") {
o.Software = "pleroma"
o.Version = "guess"
} else if strings.Contains(indexstr, "Mastodon") {
o.Software = "mastodon"
o.Version = "guess"
} else if strings.Contains(indexstr, "Gab") {
o.Software = "gab"
o.Version = "guess"
} else { } else {
defer misskey_api_resp.Body.Close()
}
if misskey_api_resp.StatusCode == 200 {
err = json.NewDecoder(misskey_api_resp.Body).Decode(&nodeinfo)
if err == nil {
o.Software = nodeinfo.Software.Name
o.Version = nodeinfo.Software.Version
o.LastRun = time.Now().Format(time.RFC3339)
defer misskey_api_resp.Body.Close()
return o
}
}
o.Software = "Unsupported" o.Software = "Unsupported"
o.Version = "Unknown" o.Version = "Unknown"
}
return o return o
} }
func LogInstance(endpoint string, o shared.RunningInstance) bool { func LogInstance(endpoint string, o shared.RunningInstance) bool {
logDebug("LogInstance: ", endpoint)
selectRet := pool.QueryRow(context.Background(), "SELECT FROM instances WHERE endpoint = $1", endpoint) selectRet := pool.QueryRow(context.Background(), "SELECT FROM instances WHERE endpoint = $1", endpoint)
err := selectRet.Scan() err := selectRet.Scan()
if err == nil { if err == nil {
@ -184,7 +176,7 @@ func LogInstance(endpoint string, o shared.RunningInstance) bool {
} }
func CheckInstance(newinstance string, callerEndpoint string) { func CheckInstance(newinstance string, callerEndpoint string) {
logDebug("checkInstance for ", newinstance) logDebug("checkInstance: ", newinstance)
if settings.Crawl == true { if settings.Crawl == true {
// Skip over this if its the same as the endpoint or empty // Skip over this if its the same as the endpoint or empty
if newinstance == callerEndpoint || newinstance == "" { if newinstance == callerEndpoint || newinstance == "" {
@ -251,7 +243,7 @@ func StartInstance(endpoint string) {
if o.Software == "pleroma" { if o.Software == "pleroma" {
logConn("Starting " + endpoint + " as " + o.Software + " " + o.Version) logConn("Starting " + endpoint + " as " + o.Software + " " + o.Version)
o.CaptureType = "Poll" o.CaptureType = "Stream"
UpdateRunner(endpoint, o) UpdateRunner(endpoint, o)
// PollMastodonPleroma(endpoint, &o) // PollMastodonPleroma(endpoint, &o)
StreamPleroma(endpoint) StreamPleroma(endpoint)
@ -260,6 +252,10 @@ func StartInstance(endpoint string) {
o.CaptureType = "Stream" o.CaptureType = "Stream"
UpdateRunner(endpoint, o) UpdateRunner(endpoint, o)
StreamMastodon(endpoint, &o) StreamMastodon(endpoint, &o)
} else if o.Software == "misskey" {
logConn("Starting " + endpoint + " as " + o.Software + " " + o.Version)
o.CaptureType = "Stream"
UpdateRunner(endpoint, o)
} else { } else {
o.Status = 605 o.Status = 605
UpdateRunner(endpoint, o) UpdateRunner(endpoint, o)

View File

@ -34,6 +34,13 @@ func StreamPleroma(endpoint string) {
return return
} }
ri_mutex.Lock()
m := runninginstances[endpoint]
m.Status = shared.RUNNING
m.LastRun = "Streaming"
runninginstances[endpoint] = m
ri_mutex.Unlock()
for { for {
logDebug("Starting loop for ", endpoint) logDebug("Starting loop for ", endpoint)
_, p, err := ws.ReadMessage() _, p, err := ws.ReadMessage()