diff --git a/contrib/backends/srndv2/src/srnd/daemon.go b/contrib/backends/srndv2/src/srnd/daemon.go index 28a3c8e..7969ef9 100644 --- a/contrib/backends/srndv2/src/srnd/daemon.go +++ b/contrib/backends/srndv2/src/srnd/daemon.go @@ -874,7 +874,7 @@ func (self *NNTPDaemon) poll(worker int) { // send to frontend if self.frontend != nil { if self.frontend.AllowNewsgroup(group) { - self.frontend.PostsChan() <- frontendPost{msgid, ref, group} + self.frontend.HandleNewPost(frontendPost{msgid, ref, group}) } } } diff --git a/contrib/backends/srndv2/src/srnd/frontend.go b/contrib/backends/srndv2/src/srnd/frontend.go index 7b52daa..d750b4f 100644 --- a/contrib/backends/srndv2/src/srnd/frontend.go +++ b/contrib/backends/srndv2/src/srnd/frontend.go @@ -25,8 +25,8 @@ func (p frontendPost) Newsgroup() string { // frontend interface for any type of frontend type Frontend interface { - // channel that is for the frontend to pool for new posts from the nntpd - PostsChan() chan frontendPost + // handle new post from nntpd + HandleNewPost(p frontendPost) // run mainloop Mainloop() @@ -36,6 +36,7 @@ type Frontend interface { // trigger a manual regen of indexes for a root post Regen(msg ArticleEntry) + // regenerate on mod event RegenOnModEvent(newsgroup, msgid, root string, page int) } diff --git a/contrib/backends/srndv2/src/srnd/frontend_http.go b/contrib/backends/srndv2/src/srnd/frontend_http.go index 2572b50..299a417 100644 --- a/contrib/backends/srndv2/src/srnd/frontend_http.go +++ b/contrib/backends/srndv2/src/srnd/frontend_http.go @@ -171,13 +171,12 @@ func (lc *liveChan) handleMessage(front *httpFrontend, cmd *liveCommand) { } type httpFrontend struct { - modui ModUI - httpmux *mux.Router - daemon *NNTPDaemon - cache CacheInterface - recvpostchan chan frontendPost - bindaddr string - name string + modui ModUI + httpmux *mux.Router + daemon *NNTPDaemon + cache CacheInterface + bindaddr string + name string secret string @@ -222,10 +221,6 @@ func (self httpFrontend) AllowNewsgroup(group string) bool { return newsgroupValidFormat(group) || group == "ctl" && !strings.HasSuffix(group, ".") } -func (self httpFrontend) PostsChan() chan frontendPost { - return self.recvpostchan -} - func (self *httpFrontend) Regen(msg ArticleEntry) { self.cache.Regen(msg) } @@ -406,33 +401,33 @@ func (self *httpFrontend) poll() { } else { log.Println("failed to register mod message, file was not opened") } - case nntp := <-self.recvpostchan: - // get root post and tell frontend to regen that thread - msgid := nntp.MessageID() - group := nntp.Newsgroup() - ref := nntp.Reference() - self.informLiveUI(msgid, ref, group) - if len(ref) > 0 { - msgid = ref - } - entry := ArticleEntry{msgid, group} - // regnerate thread - self.regenThreadChan <- entry - // regen the newsgroup we're in - // TODO: regen only what we need to - pages := self.daemon.database.GetGroupPageCount(group) - // regen all pages - var page int64 - for ; page < pages; page++ { - req := groupRegenRequest{ - group: group, - page: int(page), - } - self.regenGroupChan <- req - } } } } +func (self *httpFrontend) HandleNewPost(nntp frontendPost) { + msgid := nntp.MessageID() + group := nntp.Newsgroup() + ref := nntp.Reference() + go self.informLiveUI(msgid, ref, group) + if len(ref) > 0 { + msgid = ref + } + entry := ArticleEntry{msgid, group} + // regnerate thread + self.regenThreadChan <- entry + // regen the newsgroup we're in + // TODO: regen only what we need to + pages := self.daemon.database.GetGroupPageCount(group) + // regen all pages + var page int64 + for ; page < pages; page++ { + req := groupRegenRequest{ + group: group, + page: int(page), + } + self.regenGroupChan <- req + } +} // create a new captcha, return as json object func (self *httpFrontend) new_captcha_json(wr http.ResponseWriter, r *http.Request) { @@ -1569,7 +1564,7 @@ func NewHTTPFrontend(daemon *NNTPDaemon, cache CacheInterface, config map[string Path: front.prefix, MaxAge: 600, } - front.recvpostchan = make(chan frontendPost) + front.regenThreadChan = front.cache.GetThreadChan() front.regenGroupChan = front.cache.GetGroupChan() diff --git a/contrib/backends/srndv2/src/srnd/frontend_multi.go b/contrib/backends/srndv2/src/srnd/frontend_multi.go index 6365c80..aae0e1f 100644 --- a/contrib/backends/srndv2/src/srnd/frontend_multi.go +++ b/contrib/backends/srndv2/src/srnd/frontend_multi.go @@ -7,8 +7,7 @@ package srnd // muxed frontend for holding many frontends type multiFrontend struct { - muxedpostchan chan frontendPost - frontends []Frontend + frontends []Frontend } func (self multiFrontend) AllowNewsgroup(newsgroup string) bool { @@ -25,25 +24,12 @@ func (self multiFrontend) Mainloop() { for idx := range self.frontends { go self.frontends[idx].Mainloop() } - - // poll for incoming - chnl := self.PostsChan() - for { - select { - case nntp := <-chnl: - for _, frontend := range self.frontends { - if frontend.AllowNewsgroup(nntp.Newsgroup()) { - ch := frontend.PostsChan() - ch <- nntp - } - } - break - } - } } -func (self multiFrontend) PostsChan() chan frontendPost { - return self.muxedpostchan +func (self multiFrontend) HandleNewPost(nntp frontendPost) { + for idx := range self.frontends { + self.frontends[idx].HandleNewPost(nntp) + } } func (self multiFrontend) RegenOnModEvent(newsgroup, msgid, root string, page int) { @@ -54,7 +40,6 @@ func (self multiFrontend) RegenOnModEvent(newsgroup, msgid, root string, page in func MuxFrontends(fronts ...Frontend) Frontend { var front multiFrontend - front.muxedpostchan = make(chan frontendPost, 64) front.frontends = fronts return front }