Turn CHATHISTORY and backlog limits into constants

This commit is contained in:
Simon Ser 2021-11-03 18:29:21 +01:00
parent 0b6b687d70
commit abe5f362db
2 changed files with 5 additions and 6 deletions

View File

@ -1161,7 +1161,7 @@ func (dc *downstreamConn) welcome() error {
} }
isupport := []string{ isupport := []string{
fmt.Sprintf("CHATHISTORY=%v", dc.srv.HistoryLimit), fmt.Sprintf("CHATHISTORY=%v", chatHistoryLimit),
"CASEMAPPING=ascii", "CASEMAPPING=ascii",
} }
@ -1331,9 +1331,8 @@ func (dc *downstreamConn) sendTargetBacklog(net *network, target, msgID string)
ctx, cancel := context.WithTimeout(context.TODO(), messageStoreTimeout) ctx, cancel := context.WithTimeout(context.TODO(), messageStoreTimeout)
defer cancel() defer cancel()
limit := 4000
targetCM := net.casemap(target) 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 { if err != nil {
dc.logger.Printf("failed to send backlog for %q: %v", target, err) dc.logger.Printf("failed to send backlog for %q: %v", target, err)
return return
@ -2328,7 +2327,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
} }
limit, err := strconv.Atoi(limitStr) 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{ return ircError{&irc.Message{
Command: "FAIL", Command: "FAIL",
Params: []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, limitStr, "Invalid limit"}, Params: []string{"CHATHISTORY", "INVALID_PARAMS", subcommand, limitStr, "Invalid limit"},

View File

@ -26,6 +26,8 @@ var writeTimeout = 10 * time.Second
var upstreamMessageDelay = 2 * time.Second var upstreamMessageDelay = 2 * time.Second
var upstreamMessageBurst = 10 var upstreamMessageBurst = 10
var messageStoreTimeout = 10 * time.Second var messageStoreTimeout = 10 * time.Second
var chatHistoryLimit = 1000
var backlogLimit = 4000
type Logger interface { type Logger interface {
Print(v ...interface{}) Print(v ...interface{})
@ -53,7 +55,6 @@ type Server struct {
Hostname string Hostname string
Title string Title string
Logger Logger Logger Logger
HistoryLimit int
LogPath string LogPath string
Debug bool Debug bool
HTTPOrigins []string HTTPOrigins []string
@ -75,7 +76,6 @@ type Server struct {
func NewServer(db Database) *Server { func NewServer(db Database) *Server {
srv := &Server{ srv := &Server{
Logger: log.New(log.Writer(), "", log.LstdFlags), Logger: log.New(log.Writer(), "", log.LstdFlags),
HistoryLimit: 1000,
MaxUserNetworks: -1, MaxUserNetworks: -1,
db: db, db: db,
listeners: make(map[net.Listener]struct{}), listeners: make(map[net.Listener]struct{}),