From abe5f362db667f47d331e08ec8a3ddaff7e8aaa3 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 3 Nov 2021 18:29:21 +0100 Subject: [PATCH] Turn CHATHISTORY and backlog limits into constants --- downstream.go | 7 +++---- server.go | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/downstream.go b/downstream.go index 569831f..f7de0ee 100644 --- a/downstream.go +++ b/downstream.go @@ -1161,7 +1161,7 @@ func (dc *downstreamConn) welcome() error { } isupport := []string{ - fmt.Sprintf("CHATHISTORY=%v", dc.srv.HistoryLimit), + fmt.Sprintf("CHATHISTORY=%v", chatHistoryLimit), "CASEMAPPING=ascii", } @@ -1331,9 +1331,8 @@ func (dc *downstreamConn) sendTargetBacklog(net *network, target, msgID string) ctx, cancel := context.WithTimeout(context.TODO(), messageStoreTimeout) defer cancel() - limit := 4000 targetCM := net.casemap(target) - history, err := dc.user.msgStore.LoadLatestID(ctx, &net.Network, targetCM, msgID, limit) + history, err := dc.user.msgStore.LoadLatestID(ctx, &net.Network, targetCM, msgID, backlogLimit) if err != nil { dc.logger.Printf("failed to send backlog for %q: %v", target, err) return @@ -2328,7 +2327,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { } limit, err := strconv.Atoi(limitStr) - if err != nil || limit < 0 || limit > dc.srv.HistoryLimit { + if err != nil || limit < 0 || limit > chatHistoryLimit { return ircError{&irc.Message{ Command: "FAIL", Params: []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, limitStr, "Invalid limit"}, diff --git a/server.go b/server.go index bb51dfd..ea83b95 100644 --- a/server.go +++ b/server.go @@ -26,6 +26,8 @@ var writeTimeout = 10 * time.Second var upstreamMessageDelay = 2 * time.Second var upstreamMessageBurst = 10 var messageStoreTimeout = 10 * time.Second +var chatHistoryLimit = 1000 +var backlogLimit = 4000 type Logger interface { Print(v ...interface{}) @@ -53,7 +55,6 @@ type Server struct { Hostname string Title string Logger Logger - HistoryLimit int LogPath string Debug bool HTTPOrigins []string @@ -75,7 +76,6 @@ type Server struct { func NewServer(db Database) *Server { srv := &Server{ Logger: log.New(log.Writer(), "", log.LstdFlags), - HistoryLimit: 1000, MaxUserNetworks: -1, db: db, listeners: make(map[net.Listener]struct{}),