From 59068bb961dcf4a5072f565c432f46e6c305beaf Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 29 Jan 2019 06:57:08 -0500 Subject: [PATCH] eh --- contrib/backends/srndv2/src/srnd/mod.go | 35 ++++++++++------------- contrib/backends/srndv2/src/srnd/store.go | 6 ++-- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/contrib/backends/srndv2/src/srnd/mod.go b/contrib/backends/srndv2/src/srnd/mod.go index 099b3ae..42c3406 100644 --- a/contrib/backends/srndv2/src/srnd/mod.go +++ b/contrib/backends/srndv2/src/srnd/mod.go @@ -198,8 +198,6 @@ type ModEngine interface { AllowBan(pubkey string) bool // allow janitor AllowJanitor(pubkey string) bool - // load a mod message - LoadMessage(msgid string) NNTPMessage // execute 1 mod action line by a mod with pubkey Execute(ev ModEvent, pubkey string) // do a mod event unconditionally @@ -227,10 +225,6 @@ func (self *modEngine) MarkSpam(msgid string) (err error) { return } -func (self *modEngine) LoadMessage(msgid string) NNTPMessage { - return self.store.GetMessage(msgid) -} - func (self *modEngine) BanAddress(cidr string) (err error) { return self.database.BanAddr(cidr) } @@ -345,22 +339,23 @@ func (self *modEngine) AllowDelete(pubkey, msgid string) (allow bool) { } func (mod *modEngine) HandleMessage(msgid string) { - nntp := mod.store.GetMessage(msgid) - if nntp == nil { - log.Println("failed to load", msgid, "in mod engine, missing message") - return - } - // sanity check - if nntp.Newsgroup() == "ctl" { - pubkey := nntp.Pubkey() - for _, line := range strings.Split(nntp.Message(), "\n") { - line = strings.Trim(line, "\r\t\n ") - if len(line) > 0 { - ev := ParseModEvent(line) - mod.Execute(ev, pubkey) + mod.store.GetMessage(msgid, func(nntp NNTPMessage) { + if nntp == nil { + log.Println("failed to load", msgid, "in mod engine, missing message") + return + } + // sanity check + if nntp.Newsgroup() == "ctl" { + pubkey := nntp.Pubkey() + for _, line := range strings.Split(nntp.Message(), "\n") { + line = strings.Trim(line, "\r\t\n ") + if len(line) > 0 { + ev := ParseModEvent(line) + mod.Execute(ev, pubkey) + } } } - } + }) } func (mod *modEngine) Do(ev ModEvent) { diff --git a/contrib/backends/srndv2/src/srnd/store.go b/contrib/backends/srndv2/src/srnd/store.go index 8887c75..930e885 100644 --- a/contrib/backends/srndv2/src/srnd/store.go +++ b/contrib/backends/srndv2/src/srnd/store.go @@ -75,7 +75,7 @@ type ArticleStore interface { // register signed message RegisterSigned(msgid, pk string) error - GetMessage(msgid string) NNTPMessage + GetMessage(msgid string, visit func(NNTPMessage)) // get size of message on disk GetMessageSize(msgid string) (int64, error) @@ -584,7 +584,7 @@ func (self *articleStore) ProcessMessage(wr io.Writer, msg io.Reader, spamfilter return } -func (self *articleStore) GetMessage(msgid string) (nntp NNTPMessage) { +func (self *articleStore) GetMessage(msgid string, visit func(NNTPMessage)) { r, err := self.OpenMessage(msgid) if err == nil { defer r.Close() @@ -597,7 +597,7 @@ func (self *articleStore) GetMessage(msgid string) (nntp NNTPMessage) { // inject pubkey for mod n.Headers().Set("X-PubKey-Ed25519", hdr.Get("X-PubKey-Ed25519")) } - nntp = n + visit(n) }) } }