From 387f3210fa9a3771e6a38f5d241db54f99e86eda Mon Sep 17 00:00:00 2001 From: Farhan Khan Date: Wed, 15 Dec 2021 19:38:58 -0500 Subject: [PATCH 1/3] No need to export Tag element --- fedilogue/retrieve.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fedilogue/retrieve.go b/fedilogue/retrieve.go index 04f9220..6f97571 100644 --- a/fedilogue/retrieve.go +++ b/fedilogue/retrieve.go @@ -64,7 +64,7 @@ type PostJson struct { Published time.Time `json:"published"` Source string `json:"source"` Summary string `json:"summary"` - Tag []TagType `json:"tag"` + tag []TagType `json:"tag"` To []string `json:"to"` Type string `json:"type"` @@ -150,7 +150,7 @@ func check_activity(uri string) { activityjson.normalized = spaceReg.ReplaceAllString(activityjson.normalized, " ") var hashtags []string - for _, tag := range activityjson.Tag { + for _, tag := range activityjson.tag { if tag.Type == "Hashtag" { hashtags = append(hashtags, strings.ToLower(tag.Name)) } From f5b9285e4439eb909f37d80449dadb409d84a0b2 Mon Sep 17 00:00:00 2001 From: Farhan Khan Date: Wed, 15 Dec 2021 23:18:59 -0500 Subject: [PATCH 2/3] Added in a staggered start of new instances Reverted exporting the Tag element of activity post --- fedilogue/fedilogue.go | 6 ++++-- fedilogue/instance.go | 11 +++++++++++ fedilogue/retrieve.go | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/fedilogue/fedilogue.go b/fedilogue/fedilogue.go index 3baf6af..702797b 100644 --- a/fedilogue/fedilogue.go +++ b/fedilogue/fedilogue.go @@ -82,6 +82,7 @@ func main() { removeHTMLReg = regexp.MustCompile(`<\/?\s*br\s*>`) re = regexp.MustCompile("^https?://([^/]*)/(.*)$") matchurl = regexp.MustCompile("http?s://[\\w\\-]+\\.[\\w\\-]+\\S*") + staggeredStartChan = make(chan bool) // Start instances located in database rows, err := pool.Query(context.Background(), "SELECT endpoint FROM instances") @@ -91,6 +92,9 @@ func main() { } defer rows.Close() + go staggeredStart(); + go statusReportHandler() + for rows.Next() { var endpoint string err = rows.Scan(&endpoint) @@ -100,14 +104,12 @@ func main() { } _, exists := GetRunner(endpoint) if exists == false { - logInfo("Autostarting " + endpoint) go StartInstance(endpoint) } } go startctl() //go webmain() - go statusReportHandler() runtime.Goexit() } diff --git a/fedilogue/instance.go b/fedilogue/instance.go index 1b69116..ebc2b48 100644 --- a/fedilogue/instance.go +++ b/fedilogue/instance.go @@ -14,6 +14,8 @@ import ( "fmt" ) +var staggeredStartChan chan bool + func DoTries(o *RunningInstance, req *http.Request) (*http.Response, error) { var resp *http.Response var err error @@ -212,8 +214,17 @@ func CheckInstance(newinstance string, callerEndpoint string) { } } +func staggeredStart() { + for { + _ :<- staggeredStartChan + time.Sleep(500 * time.Millisecond) + } +} func StartInstance(endpoint string) { + staggeredStartChan <- true + logInfo("Starting " + endpoint) + // Check if exists. If so, get the object. If not, create it o, _ := GetRunner(endpoint) diff --git a/fedilogue/retrieve.go b/fedilogue/retrieve.go index 6f97571..04f9220 100644 --- a/fedilogue/retrieve.go +++ b/fedilogue/retrieve.go @@ -64,7 +64,7 @@ type PostJson struct { Published time.Time `json:"published"` Source string `json:"source"` Summary string `json:"summary"` - tag []TagType `json:"tag"` + Tag []TagType `json:"tag"` To []string `json:"to"` Type string `json:"type"` @@ -150,7 +150,7 @@ func check_activity(uri string) { activityjson.normalized = spaceReg.ReplaceAllString(activityjson.normalized, " ") var hashtags []string - for _, tag := range activityjson.tag { + for _, tag := range activityjson.Tag { if tag.Type == "Hashtag" { hashtags = append(hashtags, strings.ToLower(tag.Name)) } From 056e89beed60cd74fe1ce5d3706619419c530872 Mon Sep 17 00:00:00 2001 From: Farhan Khan Date: Thu, 16 Dec 2021 18:19:21 -0500 Subject: [PATCH 3/3] Tagging bots in actors table --- fedilogue/retrieve.go | 14 +++++++++++++- fedilogue/tables.sql | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/fedilogue/retrieve.go b/fedilogue/retrieve.go index 04f9220..21905d4 100644 --- a/fedilogue/retrieve.go +++ b/fedilogue/retrieve.go @@ -241,7 +241,19 @@ func check_actor(uri string) int { return 406 // Unable to unmarshal body of message } - _, err = pool.Exec(context.Background(), "INSERT INTO actors (document, instance) VALUES($1, $2)", jsondocument, actorjson.instance) + var bot bool + if actorjson.Type == "Service" { + bot = true + } else { + bot = false + for _, botinstance := range settings.Alwaysbot { + if strings.Index(uri, "https://"+botinstance+"/") == 0 { + bot = true + } + } + } + + _, err = pool.Exec(context.Background(), "INSERT INTO actors (document, instance, bot) VALUES($1, $2, $3)", jsondocument, actorjson.instance, bot) if err != nil { logWarn("Error inserting %s into `actors`: "+uri, err) return 407 // Unable to insert actor diff --git a/fedilogue/tables.sql b/fedilogue/tables.sql index 9fae4f8..2399ad5 100644 --- a/fedilogue/tables.sql +++ b/fedilogue/tables.sql @@ -2,7 +2,8 @@ CREATE TABLE IF NOT EXISTS actors ( id SERIAL PRIMARY KEY, document JSONB, identifiedat TIMESTAMP with time zone DEFAULT now(), - instance VARCHAR(1000) NOT NULL + instance VARCHAR(1000) NOT NULL, + bot BOOL DEFAULT FALSE ); CREATE TABLE IF NOT EXISTS activities (