Live tracking bug fixes
This commit is contained in:
parent
4dde79f6e2
commit
91e607ae6c
fedilogue
@ -40,9 +40,11 @@ func StatusReport() {
|
||||
|
||||
mastodon := 0
|
||||
pleroma := 0
|
||||
misskey := 0
|
||||
other := 0
|
||||
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 {
|
||||
running = running + 1
|
||||
} else if o.Status == 607 { // Keepalive
|
||||
@ -55,12 +57,14 @@ func StatusReport() {
|
||||
mastodon = mastodon + 1
|
||||
} else if o.Software == "pleroma" && o.Status == 200 {
|
||||
pleroma = pleroma + 1
|
||||
} else if o.Software == "misskey" && o.Status == 200 {
|
||||
misskey = misskey + 1
|
||||
} else if o.Status == 200 {
|
||||
other = other + 1
|
||||
}
|
||||
}
|
||||
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() {
|
||||
|
@ -4,12 +4,10 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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 {
|
||||
logDebug("BuildClient for ", endpoint)
|
||||
// Test: TestBuildClient, TestBuildClientProxy
|
||||
/* The seemingly unused 'endpoint' variable is for proxying based on endpoint, ie for Tor */
|
||||
tr := &http.Transport{
|
||||
@ -99,16 +98,18 @@ func UpdateRunner(endpoint string, o shared.RunningInstance) {
|
||||
|
||||
func GetInstanceInfo(endpoint string, o shared.RunningInstance) shared.RunningInstance {
|
||||
/* Checking order
|
||||
* Mastodon/Pleroma
|
||||
* Mastodon/Pleroma/Misskey
|
||||
* Um..nothing else yet
|
||||
*/
|
||||
logDebug("GetInstanceInfo for ", endpoint)
|
||||
var nodeinfo shared.NodeInfo
|
||||
pleromastodon_nodeinfo_uri := "https://" + endpoint + "/nodeinfo/2.0.json"
|
||||
|
||||
req, _ := http.NewRequest("GET", pleromastodon_nodeinfo_uri, nil)
|
||||
req.Header.Set("User-Agent", "Tusky")
|
||||
// Checking Mastodon and Pleroma (with .json)
|
||||
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 {
|
||||
o.Software = "Unsupported"
|
||||
return o
|
||||
@ -127,47 +128,38 @@ func GetInstanceInfo(endpoint string, o shared.RunningInstance) shared.RunningIn
|
||||
}
|
||||
}
|
||||
|
||||
// Check the front page
|
||||
index_uri := "https://" + endpoint + "/"
|
||||
req, _ = http.NewRequest("GET", index_uri, nil)
|
||||
// Checking for Misskey (without .json)
|
||||
misskey_nodeinfo_uri := "https://" + endpoint + "/nodeinfo/2.0"
|
||||
req, _ := http.NewRequest("GET", misskey_nodeinfo_uri, nil)
|
||||
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 {
|
||||
o.Status = shared.UNSUPPORTED_INSTANCE
|
||||
o.Software = "Unsupported"
|
||||
logWarn("Unable to read index of " + endpoint + ", giving up")
|
||||
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 {
|
||||
o.Software = "Unsupported"
|
||||
o.Version = "Unknown"
|
||||
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.Version = "Unknown"
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func LogInstance(endpoint string, o shared.RunningInstance) bool {
|
||||
logDebug("LogInstance: ", endpoint)
|
||||
selectRet := pool.QueryRow(context.Background(), "SELECT FROM instances WHERE endpoint = $1", endpoint)
|
||||
err := selectRet.Scan()
|
||||
if err == nil {
|
||||
@ -184,7 +176,7 @@ func LogInstance(endpoint string, o shared.RunningInstance) bool {
|
||||
}
|
||||
|
||||
func CheckInstance(newinstance string, callerEndpoint string) {
|
||||
logDebug("checkInstance for ", newinstance)
|
||||
logDebug("checkInstance: ", newinstance)
|
||||
if settings.Crawl == true {
|
||||
// Skip over this if its the same as the endpoint or empty
|
||||
if newinstance == callerEndpoint || newinstance == "" {
|
||||
@ -251,7 +243,7 @@ func StartInstance(endpoint string) {
|
||||
|
||||
if o.Software == "pleroma" {
|
||||
logConn("Starting " + endpoint + " as " + o.Software + " " + o.Version)
|
||||
o.CaptureType = "Poll"
|
||||
o.CaptureType = "Stream"
|
||||
UpdateRunner(endpoint, o)
|
||||
// PollMastodonPleroma(endpoint, &o)
|
||||
StreamPleroma(endpoint)
|
||||
@ -260,6 +252,10 @@ func StartInstance(endpoint string) {
|
||||
o.CaptureType = "Stream"
|
||||
UpdateRunner(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 {
|
||||
o.Status = 605
|
||||
UpdateRunner(endpoint, o)
|
||||
|
@ -34,6 +34,13 @@ func StreamPleroma(endpoint string) {
|
||||
return
|
||||
}
|
||||
|
||||
ri_mutex.Lock()
|
||||
m := runninginstances[endpoint]
|
||||
m.Status = shared.RUNNING
|
||||
m.LastRun = "Streaming"
|
||||
runninginstances[endpoint] = m
|
||||
ri_mutex.Unlock()
|
||||
|
||||
for {
|
||||
logDebug("Starting loop for ", endpoint)
|
||||
_, p, err := ws.ReadMessage()
|
||||
|
Loading…
x
Reference in New Issue
Block a user