From 2e4a5eeac04f8235417b907157760a3a0eee8a29 Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+samtv12345@users.noreply.github.com> Date: Wed, 12 Nov 2025 20:22:23 +0100 Subject: [PATCH 1/2] chore: separate database --- lib/api/author/init.go | 6 +- lib/api/init.go | 8 +- lib/api/pad/init.go | 16 +-- lib/api/utils/pad.go | 6 +- lib/author/authorManager.go | 6 +- lib/db/DirtyDB.go | 4 +- lib/models/pad/Pad.go | 16 +-- lib/pad/SecurityManager.go | 16 +-- lib/pad/SessionManager.go | 8 +- lib/pad/padManager.go | 32 ++--- lib/pad/readOnlyManager.go | 4 +- lib/pad/webaccess.go | 6 +- lib/session/MemoryStore.go | 10 +- lib/settings/DBType.go | 28 +++++ lib/settings/Settings.go | 4 +- lib/settings/clientVars/clientVars.go | 13 +- lib/settings/viper.go | 9 +- lib/utils/{globals.go => dbBootstrap.go} | 29 ++--- lib/ws/PadMessageHandler.go | 149 ++++++++++++----------- lib/ws/client.go | 21 ++-- main.go | 18 ++- var/.gitkeep | 0 22 files changed, 231 insertions(+), 178 deletions(-) create mode 100644 lib/settings/DBType.go rename lib/utils/{globals.go => dbBootstrap.go} (76%) create mode 100644 var/.gitkeep diff --git a/lib/api/author/init.go b/lib/api/author/init.go index 697c93d2..3d4b8a75 100644 --- a/lib/api/author/init.go +++ b/lib/api/author/init.go @@ -2,8 +2,10 @@ package author import ( "encoding/json" + error2 "github.com/ether/etherpad-go/lib/api/error" "github.com/ether/etherpad-go/lib/author" + "github.com/ether/etherpad-go/lib/db" "github.com/gofiber/fiber/v2" ) @@ -15,8 +17,8 @@ type CreateDtoResponse struct { authorId string } -func Init(c *fiber.App) { - var authorManager author.Manager = author.NewManager() +func Init(c *fiber.App, db db.DataStore) { + var authorManager = author.NewManager(db) c.Post("/author", func(c *fiber.Ctx) error { var dto CreateDto diff --git a/lib/api/init.go b/lib/api/init.go index 3fad80ec..d90a5613 100644 --- a/lib/api/init.go +++ b/lib/api/init.go @@ -7,14 +7,16 @@ import ( "github.com/ether/etherpad-go/lib/api/groups" "github.com/ether/etherpad-go/lib/api/pad" "github.com/ether/etherpad-go/lib/api/static" + "github.com/ether/etherpad-go/lib/db" "github.com/ether/etherpad-go/lib/settings" + "github.com/ether/etherpad-go/lib/ws" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/session" ) -func InitAPI(c *fiber.App, uiAssets embed.FS, settings settings.Settings, cookieStore *session.Store) { - author.Init(c) - pad.Init(c) +func InitAPI(c *fiber.App, uiAssets embed.FS, settings settings.Settings, cookieStore *session.Store, store db.DataStore, handler *ws.PadMessageHandler) { + author.Init(c, store) + pad.Init(c, store, handler) groups.Init(c) static.Init(c, uiAssets, settings, cookieStore) } diff --git a/lib/api/pad/init.go b/lib/api/pad/init.go index 9bbe0dfe..eee7d940 100644 --- a/lib/api/pad/init.go +++ b/lib/api/pad/init.go @@ -2,15 +2,17 @@ package pad import ( "errors" + apiError "github.com/ether/etherpad-go/lib/api/error" utils2 "github.com/ether/etherpad-go/lib/api/utils" "github.com/ether/etherpad-go/lib/apool" + "github.com/ether/etherpad-go/lib/db" "github.com/ether/etherpad-go/lib/utils" "github.com/ether/etherpad-go/lib/ws" "github.com/gofiber/fiber/v2" ) -func getText(padId string, rev *string) (*string, error) { +func getText(padId string, rev *string, store db.DataStore) (*string, error) { var revNum *int = nil if rev != nil { revPoint, err := utils.CheckValidRev(*rev) @@ -20,7 +22,7 @@ func getText(padId string, rev *string) (*string, error) { } } - pad, err := utils2.GetPadSafe(padId, true, nil, nil) + pad, err := utils2.GetPadSafe(padId, true, nil, nil, store) if err != nil { return nil, err @@ -44,13 +46,13 @@ type AttributePoolResponse struct { Pool apool.APool `json:"pool"` } -func Init(c *fiber.App) { +func Init(c *fiber.App, store db.DataStore, handler *ws.PadMessageHandler) { c.Get("/pads/:padId/text", func(c *fiber.Ctx) error { return c.SendStatus(200) }) c.Get("/pads/:padId/attributePool", func(ctx *fiber.Ctx) error { var padIdToFind = ctx.Params("padId") - var padFound, err = utils2.GetPadSafe(padIdToFind, true, nil, nil) + var padFound, err = utils2.GetPadSafe(padIdToFind, true, nil, nil, store) if err != nil { return ctx.Status(404).JSON(apiError.Error{ Message: "Pad not found", @@ -74,7 +76,7 @@ func Init(c *fiber.App) { }) } - var pad, errorForPad2 = utils2.GetPadSafe(padId, true, nil, nil) + var pad, errorForPad2 = utils2.GetPadSafe(padId, true, nil, nil, store) if errorForPad2 != nil { return ctx.Status(404).JSON(apiError.Error{ Message: "Pad not found", @@ -118,7 +120,7 @@ func Init(c *fiber.App) { }) } - var pad, errPadSafe = utils2.GetPadSafe(padId, true, nil, nil) + var pad, errPadSafe = utils2.GetPadSafe(padId, true, nil, nil, store) if errPadSafe != nil { return ctx.Status(404).JSON(apiError.Error{ Message: "Pad not found", @@ -132,7 +134,7 @@ func Init(c *fiber.App) { Error: 500, }) } - ws.UpdatePadClients(pad) + handler.UpdatePadClients(pad) return ctx.SendStatus(200) }) } diff --git a/lib/api/utils/pad.go b/lib/api/utils/pad.go index effe1f40..58c952a5 100644 --- a/lib/api/utils/pad.go +++ b/lib/api/utils/pad.go @@ -2,12 +2,14 @@ package utils import ( "errors" + + "github.com/ether/etherpad-go/lib/db" pad2 "github.com/ether/etherpad-go/lib/models/pad" "github.com/ether/etherpad-go/lib/pad" ) -func GetPadSafe(padID string, shouldExist bool, text *string, authorId *string) (*pad2.Pad, error) { - var padManager = pad.NewManager() +func GetPadSafe(padID string, shouldExist bool, text *string, authorId *string, db db.DataStore) (*pad2.Pad, error) { + var padManager = pad.NewManager(db) if !padManager.IsValidPadId(padID) { return nil, errors.New("padID is not valid") diff --git a/lib/author/authorManager.go b/lib/author/authorManager.go index 3238b137..0bb9037a 100644 --- a/lib/author/authorManager.go +++ b/lib/author/authorManager.go @@ -14,9 +14,9 @@ type Manager struct { Db db.DataStore } -func NewManager() Manager { - return Manager{ - Db: utils.GetDB(), +func NewManager(db db.DataStore) *Manager { + return &Manager{ + Db: db, } } diff --git a/lib/db/DirtyDB.go b/lib/db/DirtyDB.go index 4ebc0255..b7391ab5 100644 --- a/lib/db/DirtyDB.go +++ b/lib/db/DirtyDB.go @@ -629,8 +629,8 @@ func (d SQLiteDB) GetPadMetaData(padId string, revNum int) (*db.PadMetaData, err return &padMetaData, nil } -// NewDirtyDB This function creates a new SQLiteDB and returns a pointer to it. -func NewDirtyDB(path string) (*SQLiteDB, error) { +// NewSQLiteDB This function creates a new SQLiteDB and returns a pointer to it. +func NewSQLiteDB(path string) (*SQLiteDB, error) { sqlDb, err := sql.Open("sqlite", path) if err != nil { panic(err) diff --git a/lib/models/pad/Pad.go b/lib/models/pad/Pad.go index 0a200f55..8d4ab034 100644 --- a/lib/models/pad/Pad.go +++ b/lib/models/pad/Pad.go @@ -18,14 +18,9 @@ import ( "github.com/ether/etherpad-go/lib/utils" ) -var authorManager author.Manager - -func init() { - authorManager = author.NewManager() -} - type Pad struct { db db.DataStore + authorManager *author.Manager Id string ChatHead int Head int @@ -35,10 +30,10 @@ type Pad struct { AText apool.AText } -func NewPad(id string) Pad { +func NewPad(id string, db db.DataStore) Pad { p := new(Pad) p.Id = id - p.db = utils.GetDB() + p.db = db p.Pool = apool.NewAPool() p.Head = -1 p.ChatHead = -1 @@ -155,7 +150,8 @@ func CleanText(context string) *string { return &context } -func (p *Pad) Init(text *string, author *string) error { +func (p *Pad) Init(text *string, author *string, authorManager *author.Manager) error { + p.authorManager = authorManager if author == nil { author = new(string) *author = "" @@ -329,7 +325,7 @@ func (p *Pad) AppendRevision(cs string, authorId *string) int { if authorId != nil { var clonedAuthorId = *authorId if clonedAuthorId != "" { - authorManager.AddPad(*authorId, p.Id) + p.authorManager.AddPad(*authorId, p.Id) } } diff --git a/lib/pad/SecurityManager.go b/lib/pad/SecurityManager.go index 129857cb..d36d9123 100644 --- a/lib/pad/SecurityManager.go +++ b/lib/pad/SecurityManager.go @@ -2,26 +2,28 @@ package pad import ( "errors" + "strings" + "github.com/ether/etherpad-go/lib/author" + "github.com/ether/etherpad-go/lib/db" "github.com/ether/etherpad-go/lib/models/webaccess" "github.com/ether/etherpad-go/lib/settings" "github.com/ether/etherpad-go/lib/utils" - "strings" ) type SecurityManager struct { ReadOnlyManager *ReadOnlyManager PadManager Manager - AuthorManager author.Manager + AuthorManager *author.Manager SessionManager *SessionManager } -func NewSecurityManager() SecurityManager { +func NewSecurityManager(db db.DataStore) SecurityManager { return SecurityManager{ - ReadOnlyManager: NewReadOnlyManager(), - PadManager: NewManager(), - AuthorManager: author.NewManager(), - SessionManager: NewSessionManager(), + ReadOnlyManager: NewReadOnlyManager(db), + PadManager: NewManager(db), + AuthorManager: author.NewManager(db), + SessionManager: NewSessionManager(db), } } diff --git a/lib/pad/SessionManager.go b/lib/pad/SessionManager.go index 176b6b2c..1509914d 100644 --- a/lib/pad/SessionManager.go +++ b/lib/pad/SessionManager.go @@ -1,19 +1,19 @@ package pad import ( - "github.com/ether/etherpad-go/lib/db" - "github.com/ether/etherpad-go/lib/utils" "regexp" "strings" + + "github.com/ether/etherpad-go/lib/db" ) type SessionManager struct { db db.DataStore } -func NewSessionManager() *SessionManager { +func NewSessionManager(db db.DataStore) *SessionManager { return &SessionManager{ - db: utils.GetDB(), + db, } } diff --git a/lib/pad/padManager.go b/lib/pad/padManager.go index 0453c1ba..1debd5ba 100644 --- a/lib/pad/padManager.go +++ b/lib/pad/padManager.go @@ -5,9 +5,9 @@ import ( "regexp" "unicode/utf8" + "github.com/ether/etherpad-go/lib/author" "github.com/ether/etherpad-go/lib/db" "github.com/ether/etherpad-go/lib/models/pad" - "github.com/ether/etherpad-go/lib/utils" ) var globalPadCache *GlobalPadCache @@ -20,12 +20,12 @@ type List struct { db db.DataStore } -func NewList() List { +func NewList(db db.DataStore) List { return List{ _cachedList: make([]string, 0), _list: make(map[string]interface{}), _loaded: false, - db: utils.GetDB(), + db: db, } } @@ -58,11 +58,13 @@ func (l *List) GetPads() []string { return l._cachedList } +var padRegex *regexp.Regexp + func init() { globalPadCache = &GlobalPadCache{ padCache: make(map[string]*pad.Pad), } - padList = NewList() + padRegex, _ = regexp.Compile("^(g.[a-zA-Z0-9]{16}$)?[^$]{1,50}$") } type GlobalPadCache struct { @@ -81,19 +83,19 @@ func (g *GlobalPadCache) DeletePad(padID string) { delete(g.padCache, padID) } -var padRegex *regexp.Regexp - -func init() { - padRegex, _ = regexp.Compile("^(g.[a-zA-Z0-9]{16}$)?[^$]{1,50}$") -} - type Manager struct { - store db.DataStore + store db.DataStore + author *author.Manager + padList List } -func NewManager() Manager { +func NewManager(db db.DataStore) Manager { return Manager{ - store: utils.GetDB(), + store: db, + author: &author.Manager{ + Db: db, + }, + padList: NewList(db), } } @@ -140,11 +142,11 @@ func (m *Manager) GetPad(padID string, text *string, authorId *string) (*pad.Pad } // try to load pad - var newPad = pad.NewPad(padID) + var newPad = pad.NewPad(padID, m.store) // initialize the pad - newPad.Init(text, authorId) + newPad.Init(text, authorId, m.author) globalPadCache.SetPad(padID, &newPad) return &newPad, nil diff --git a/lib/pad/readOnlyManager.go b/lib/pad/readOnlyManager.go index 2298e11c..9dab2829 100644 --- a/lib/pad/readOnlyManager.go +++ b/lib/pad/readOnlyManager.go @@ -17,9 +17,9 @@ type IdRequest struct { ReadOnly bool } -func NewReadOnlyManager() *ReadOnlyManager { +func NewReadOnlyManager(db db.DataStore) *ReadOnlyManager { return &ReadOnlyManager{ - Store: utils.GetDB(), + Store: db, } } diff --git a/lib/pad/webaccess.go b/lib/pad/webaccess.go index 1d3a9d40..0605a31d 100644 --- a/lib/pad/webaccess.go +++ b/lib/pad/webaccess.go @@ -17,9 +17,7 @@ import ( "go.uber.org/zap" ) -var readOnlyManager = NewReadOnlyManager() - -func UserCanModify(padId *string, req *webaccess.SocketClientRequest) bool { +func UserCanModify(padId *string, req *webaccess.SocketClientRequest, readOnlyManager ReadOnlyManager) bool { if readOnlyManager.isReadOnlyID(padId) { return false } @@ -43,7 +41,7 @@ func UserCanModify(padId *string, req *webaccess.SocketClientRequest) bool { return level != nil && *level != "readOnly" } -func CheckAccess(ctx *fiber.Ctx, logger *zap.SugaredLogger, retrievedSettings *settings.Settings) error { +func CheckAccess(ctx *fiber.Ctx, logger *zap.SugaredLogger, retrievedSettings *settings.Settings, readOnlyManager *ReadOnlyManager) error { var requireAdmin = strings.HasPrefix(strings.ToLower(ctx.Path()), "/admin-auth") //FIXME this needs to be set // /////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/lib/session/MemoryStore.go b/lib/session/MemoryStore.go index 9b75cf89..70f3c8bd 100644 --- a/lib/session/MemoryStore.go +++ b/lib/session/MemoryStore.go @@ -2,12 +2,12 @@ package session // src/node/db/SessionStore.ts import ( + "math" + "time" + "github.com/ether/etherpad-go/lib/db" "github.com/ether/etherpad-go/lib/models/session" - "github.com/ether/etherpad-go/lib/utils" "github.com/gofiber/fiber/v2" - "math" - "time" ) type Expiration struct { @@ -28,9 +28,9 @@ type MemoryStore struct { generate *func(c *fiber.Ctx) } -func NewMemoryStore(refresh *int64) *MemoryStore { +func NewMemoryStore(db db.DataStore, refresh *int64) *MemoryStore { return &MemoryStore{ - db: utils.GetDB(), + db: db, refresh: refresh, expirations: make(map[string]Expiration), } diff --git a/lib/settings/DBType.go b/lib/settings/DBType.go new file mode 100644 index 00000000..300974f7 --- /dev/null +++ b/lib/settings/DBType.go @@ -0,0 +1,28 @@ +package settings + +import ( + "fmt" + "strings" +) + +type IDBType string + +const ( + SQLITE IDBType = "sqlite" + MEMORY IDBType = "memory" +) + +func ParseDBType(s string) (IDBType, error) { + switch strings.ToLower(strings.TrimSpace(s)) { + case "sqlite": + return SQLITE, nil + case "memory": + return MEMORY, nil + default: + return "", fmt.Errorf("unknown DB type: %q", s) + } +} + +func (dbType IDBType) String() string { + return string(dbType) +} diff --git a/lib/settings/Settings.go b/lib/settings/Settings.go index 37b87dd1..8baa79e6 100644 --- a/lib/settings/Settings.go +++ b/lib/settings/Settings.go @@ -138,7 +138,7 @@ type Settings struct { Port string `json:"port"` SuppressErrorsInPadText bool `json:"suppressErrorsInPadText"` SSL SSLSettings `json:"ssl"` - DBType string `json:"dbType"` + DBType IDBType `json:"dbType"` DBSettings *DBSettings `json:"dbSettings"` DefaultPadText string `json:"defaultPadText"` PadOptions PadOptions `json:"padOptions"` @@ -663,7 +663,7 @@ func init() { setting, err := ReadConfig(string(settings)) if err != nil { - println("error is" + err.Error()) + println("error is " + err.Error()) return } setting.GitVersion = GitVersion() diff --git a/lib/settings/clientVars/clientVars.go b/lib/settings/clientVars/clientVars.go index 2ad0b00d..1872a998 100644 --- a/lib/settings/clientVars/clientVars.go +++ b/lib/settings/clientVars/clientVars.go @@ -14,10 +14,13 @@ import ( "github.com/ether/etherpad-go/lib/utils" ) -func NewClientVars(pad pad.Pad, sessionInfo *ws.Session, apool apool2.APool, historicalAuthorData map[string]author2.Author, retrievedSettings *settings.Settings) clientVars.ClientVars { +type Factory struct { + ReadOnlyManager *pad2.ReadOnlyManager + AuthorManager *author2.Manager +} + +func (f *Factory) NewClientVars(pad pad.Pad, sessionInfo *ws.Session, apool apool2.APool, historicalAuthorData map[string]author2.Author, retrievedSettings *settings.Settings) clientVars.ClientVars { var historyData = make(map[string]clientVars.CollabAuthor) - var readonlyManager = pad2.NewReadOnlyManager() - authorManager := author2.NewManager() for _, authorData := range historicalAuthorData { historyData[authorData.Id] = clientVars.CollabAuthor{ @@ -26,7 +29,7 @@ func NewClientVars(pad pad.Pad, sessionInfo *ws.Session, apool apool2.APool, his } } - var currentAuthor, err = authorManager.GetAuthor(sessionInfo.Author) + var currentAuthor, err = f.AuthorManager.GetAuthor(sessionInfo.Author) if err != nil { panic(err) } @@ -103,7 +106,7 @@ func NewClientVars(pad pad.Pad, sessionInfo *ws.Session, apool apool2.APool, his } var currentTime = pad.GetRevisionDate(pad.Head) - var readonlyId = readonlyManager.GetIds(&pad.Id) + var readonlyId = f.ReadOnlyManager.GetIds(&pad.Id) etherPadConvertedAttribs := make(map[string][]string) for k, v := range apool.NumToAttrib { diff --git a/lib/settings/viper.go b/lib/settings/viper.go index e9a617f3..c99aa8c4 100644 --- a/lib/settings/viper.go +++ b/lib/settings/viper.go @@ -46,7 +46,7 @@ func ReadConfig(jsonStr string) (*Settings, error) { viper.SetDefault(SocketIoMaxHttpBufferSize, 50000) viper.SetDefault(AuthenticationMethod, "sso") - viper.SetDefault(DBType, "rustydb") + viper.SetDefault(DBType, SQLITE) viper.SetDefault(DBSettingsHost, nil) viper.SetDefault(DBSettingsUser, nil) viper.SetDefault(DBSettingsPassword, nil) @@ -156,6 +156,11 @@ func ReadConfig(jsonStr string) (*Settings, error) { } } + dbTypeToUse, err := ParseDBType(viper.GetString(DBType)) + if err != nil { + return nil, err + } + s := &Settings{ Title: viper.GetString(Title), ShowRecentPads: viper.GetBool(ShowRecentPads), @@ -187,7 +192,7 @@ func ReadConfig(jsonStr string) (*Settings, error) { MaxHttpBufferSize: viper.GetInt64(SocketIoMaxHttpBufferSize), }, AuthenticationMethod: viper.GetString(AuthenticationMethod), - DBType: viper.GetString(DBType), + DBType: dbTypeToUse, DBSettings: &DBSettings{ Host: viper.GetString(DBSettingsHost), Port: viper.GetString(DBSettingsPort), diff --git a/lib/utils/globals.go b/lib/utils/dbBootstrap.go similarity index 76% rename from lib/utils/globals.go rename to lib/utils/dbBootstrap.go index c7f7d6dc..4a66e06d 100644 --- a/lib/utils/globals.go +++ b/lib/utils/dbBootstrap.go @@ -1,7 +1,7 @@ package utils import ( - "os" + "errors" "github.com/ether/etherpad-go/lib/db" plugins2 "github.com/ether/etherpad-go/lib/plugins" @@ -79,28 +79,13 @@ var ColorPalette = []string{ "#b3b3e6", } -var datastore db.DataStore - -func GetDB() db.DataStore { - if datastore == nil { - if settings.Displayed.DBType == "dirty" { - datastore, _ = db.NewDirtyDB("test.db") - } else { - var typeDB, ok = os.LookupEnv("ETHERPAD_DB_TYPE") - - if ok { - datastore = db.NewMemoryDataStore() - } else { - if typeDB == "memory" { - datastore = db.NewMemoryDataStore() - } else { - datastore, _ = db.NewDirtyDB("test.db") - } - } - } +func GetDB(retrievedSettings settings.Settings) (db.DataStore, error) { + if retrievedSettings.DBType == settings.SQLITE { + return db.NewSQLiteDB(retrievedSettings.DBSettings.Filename) + } else if retrievedSettings.DBType == settings.MEMORY { + return db.NewMemoryDataStore(), nil } - - return datastore + return nil, errors.New("unsupported database type") } var plugins = map[string]plugins2.Plugin{} diff --git a/lib/ws/PadMessageHandler.go b/lib/ws/PadMessageHandler.go index 858585e3..a21ea4ec 100644 --- a/lib/ws/PadMessageHandler.go +++ b/lib/ws/PadMessageHandler.go @@ -10,6 +10,7 @@ import ( "github.com/ether/etherpad-go/lib/apool" "github.com/ether/etherpad-go/lib/author" "github.com/ether/etherpad-go/lib/changeset" + db2 "github.com/ether/etherpad-go/lib/db" clientVars2 "github.com/ether/etherpad-go/lib/models/clientVars" "github.com/ether/etherpad-go/lib/models/db" pad2 "github.com/ether/etherpad-go/lib/models/pad" @@ -36,54 +37,66 @@ type SessionInfo struct { padId string } -var padManager pad.Manager -var readOnlyManager *pad.ReadOnlyManager -var authorManager author.Manager var colorRegEx *regexp.Regexp -var securityManager pad.SecurityManager - -func init() { - padManager = pad.NewManager() - readOnlyManager = pad.NewReadOnlyManager() - authorManager = author.NewManager() - colorRegEx, _ = regexp.Compile("^#(?:[0-9A-F]{3}){1,2}$") - securityManager = pad.NewSecurityManager() -} type Task struct { socket *Client message ws.UserChange } -var PadChannels = NewChannelOperator() - type ChannelOperator struct { channels map[string]chan Task + handler *PadMessageHandler } -func NewChannelOperator() ChannelOperator { +func NewChannelOperator(p *PadMessageHandler) ChannelOperator { return ChannelOperator{ channels: make(map[string]chan Task), + handler: p, } } func (c *ChannelOperator) AddToQueue(ch string, t Task) { - var _, ok = PadChannels.channels[ch] + var _, ok = c.channels[ch] if !ok { - PadChannels.channels[ch] = make(chan Task) + c.channels[ch] = make(chan Task) go func() { for { - var incomingTask = <-PadChannels.channels[ch] - handleUserChanges(incomingTask) + var incomingTask = <-c.channels[ch] + c.handler.handleUserChanges(incomingTask) } }() } - PadChannels.channels[ch] <- t + c.channels[ch] <- t +} + +type PadMessageHandler struct { + padManager pad.Manager + readOnlyManager *pad.ReadOnlyManager + authorManager *author.Manager + securityManager pad.SecurityManager + padChannels ChannelOperator + factory clientVars.Factory +} + +func NewPadMessageHandler(db db2.DataStore) *PadMessageHandler { + var padMessageHandler = PadMessageHandler{ + padManager: pad.NewManager(db), + readOnlyManager: pad.NewReadOnlyManager(db), + authorManager: author.NewManager(db), + securityManager: pad.NewSecurityManager(db), + factory: clientVars.Factory{ + ReadOnlyManager: pad.NewReadOnlyManager(db), + AuthorManager: author.NewManager(db), + }, + } + padMessageHandler.padChannels = NewChannelOperator(&padMessageHandler) + return &padMessageHandler } -func handleUserChanges(task Task) { +func (p *PadMessageHandler) handleUserChanges(task Task) { var wireApool = apool.NewAPool() var newAPool = apool.NewAPool() newAPool.NextNum = task.message.Data.Data.Apool.NextNum @@ -91,7 +104,7 @@ func handleUserChanges(task Task) { wireApool = *wireApool.FromJsonable(newAPool) var session = SessionStoreInstance.getSession(task.socket.SessionId) - var retrievedPad, err = padManager.GetPad(session.PadId, nil, &session.Author) + var retrievedPad, err = p.padManager.GetPad(session.PadId, nil, &session.Author) if err != nil { println("Error retrieving pad", err) return @@ -181,7 +194,7 @@ func handleUserChanges(task Task) { panic("Revision number is not within range") } - var correctionChangeset = correctMarkersInPad(retrievedPad.AText, retrievedPad.Pool) + var correctionChangeset = p.correctMarkersInPad(retrievedPad.AText, retrievedPad.Pool) if correctionChangeset != nil { retrievedPad.AppendRevision(*correctionChangeset, &session.Author) } @@ -220,10 +233,10 @@ func handleUserChanges(task Task) { session.Time = retrievedPad.GetRevisionDate(newRev) } retrievedPad.Head = newRev - UpdatePadClients(retrievedPad) + p.UpdatePadClients(retrievedPad) } -func handleMessage(message any, client *Client, ctx *fiber.Ctx, retrievedSettings *settings.Settings, logger *zap.SugaredLogger) { +func (p *PadMessageHandler) handleMessage(message any, client *Client, ctx *fiber.Ctx, retrievedSettings *settings.Settings, logger *zap.SugaredLogger) { var isSessionInfo = SessionStoreInstance.hasSession(client.SessionId) if !isSessionInfo { @@ -237,8 +250,8 @@ func handleMessage(message any, client *Client, ctx *fiber.Ctx, retrievedSetting if ok { thisSession = SessionStoreInstance.addHandleClientInformation(client.SessionId, castedMessage.Data.PadID, castedMessage.Data.Token) - if !padManager.DoesPadExist(thisSession.Auth.PadId) { - var padId, err = padManager.SanitizePadId(castedMessage.Data.PadID) + if !p.padManager.DoesPadExist(thisSession.Auth.PadId) { + var padId, err = p.padManager.SanitizePadId(castedMessage.Data.PadID) if err != nil { println("Error sanitizing pad id", err.Error()) @@ -247,7 +260,7 @@ func handleMessage(message any, client *Client, ctx *fiber.Ctx, retrievedSetting thisSession.PadId = *padId } - var padIds = readOnlyManager.GetIds(&thisSession.Auth.PadId) + var padIds = p.readOnlyManager.GetIds(&thisSession.Auth.PadId) SessionStoreInstance.addPadReadOnlyIds(client.SessionId, padIds.PadId, padIds.ReadOnlyPadId, padIds.ReadOnly) thisSession = SessionStoreInstance.getSession(client.SessionId) } @@ -271,7 +284,7 @@ func handleMessage(message any, client *Client, ctx *fiber.Ctx, retrievedSetting user = nil } - var grantedAccess, err = securityManager.CheckAccess(&auth.PadId, &auth.SessionId, &auth.Token, user) + var grantedAccess, err = p.securityManager.CheckAccess(&auth.PadId, &auth.SessionId, &auth.Token, user) if err != nil { var arr = make([]interface{}, 2) @@ -309,7 +322,7 @@ func handleMessage(message any, client *Client, ctx *fiber.Ctx, retrievedSetting switch expectedType := message.(type) { case ws.ClientReady: { - HandleClientReadyMessage(expectedType, client, thisSessionNewRetrieved, retrievedSettings, logger) + p.HandleClientReadyMessage(expectedType, client, thisSessionNewRetrieved, retrievedSettings, logger) return } case ws.ChatMessage: @@ -318,7 +331,7 @@ func handleMessage(message any, client *Client, ctx *fiber.Ctx, retrievedSetting var currMillis = time.Now().UnixMilli() chatMessage.Time = &currMillis chatMessage.AuthorId = &thisSession.Author - SendChatMessageToPadClients(thisSession, chatMessage) + p.SendChatMessageToPadClients(thisSession, chatMessage) } case ws.UserChange: { @@ -327,7 +340,7 @@ func handleMessage(message any, client *Client, ctx *fiber.Ctx, retrievedSetting return } - PadChannels.AddToQueue(client.Room, Task{ + p.padChannels.AddToQueue(client.Room, Task{ message: expectedType, socket: client, }) @@ -350,7 +363,7 @@ func handleMessage(message any, client *Client, ctx *fiber.Ctx, retrievedSetting return } - retrievedPad, err := padManager.GetPad(thisSession.PadId, nil, &thisSession.Author) + retrievedPad, err := p.padManager.GetPad(thisSession.PadId, nil, &thisSession.Author) if err != nil { println("Error retrieving pad for chat messages", err) return @@ -393,19 +406,19 @@ func handleMessage(message any, client *Client, ctx *fiber.Ctx, retrievedSetting } case UserInfoUpdate: { - HandleUserInfoUpdate(expectedType, client) + p.HandleUserInfoUpdate(expectedType, client) } case PadDelete: { - HandlePadDelete(client, expectedType) + p.HandlePadDelete(client, expectedType) } default: println("Unknown message type received") } } -func SendChatMessageToPadClients(session *ws.Session, chatMessage ws.ChatMessageData) { - var retrievedPad, err = padManager.GetPad(session.PadId, nil, chatMessage.AuthorId) +func (p *PadMessageHandler) SendChatMessageToPadClients(session *ws.Session, chatMessage ws.ChatMessageData) { + var retrievedPad, err = p.padManager.GetPad(session.PadId, nil, chatMessage.AuthorId) if err != nil { println("Error retrieving pad for chat message", err) return @@ -413,14 +426,14 @@ func SendChatMessageToPadClients(session *ws.Session, chatMessage ws.ChatMessage // pad.appendChatMessage() ignores the displayName property so we don't need to wait for // authorManager.getAuthorName() to resolve before saving the message to the database. retrievedPad.AppendChatMessage(chatMessage.AuthorId, *chatMessage.Time, chatMessage.Text) - authorName, err := authorManager.GetAuthorName(*chatMessage.AuthorId) + authorName, err := p.authorManager.GetAuthorName(*chatMessage.AuthorId) if err != nil { println("Error retrieving author name for chat message", err) } if authorName != nil && *authorName != "" { chatMessage.DisplayName = authorName } - for _, socket := range GetRoomSockets(session.PadId) { + for _, socket := range p.GetRoomSockets(session.PadId) { var arr = make([]interface{}, 2) arr[0] = "message" arr[1] = ws.ChatBroadCastMessage{ @@ -446,7 +459,7 @@ func SendChatMessageToPadClients(session *ws.Session, chatMessage ws.ChatMessage } } -func HandlePadDelete(client *Client, padDeleteMessage PadDelete) { +func (p *PadMessageHandler) HandlePadDelete(client *Client, padDeleteMessage PadDelete) { var session = SessionStoreInstance.getSession(client.SessionId) if session == nil || session.Author == "" || session.PadId == "" { @@ -454,12 +467,12 @@ func HandlePadDelete(client *Client, padDeleteMessage PadDelete) { return } - var retrievedPad = padManager.DoesPadExist(padDeleteMessage.Data.PadID) + var retrievedPad = p.padManager.DoesPadExist(padDeleteMessage.Data.PadID) if !retrievedPad { println("Pad does not exist") return } - var retrievedPadObj, err = padManager.GetPad(padDeleteMessage.Data.PadID, nil, nil) + var retrievedPadObj, err = p.padManager.GetPad(padDeleteMessage.Data.PadID, nil, nil) if err != nil { println("Error retrieving pad") return @@ -477,10 +490,10 @@ func HandlePadDelete(client *Client, padDeleteMessage PadDelete) { } retrievedPadObj.Remove() - KickSessionsFromPad(retrievedPadObj.Id) + p.KickSessionsFromPad(retrievedPadObj.Id) // remove the readonly entries - var readonlyId = readOnlyManager.GetReadOnlyId(retrievedPadObj.Id) - err = readOnlyManager.RemoveReadOnlyPad(readonlyId, retrievedPadObj.Id) + var readonlyId = p.readOnlyManager.GetReadOnlyId(retrievedPadObj.Id) + err = p.readOnlyManager.RemoveReadOnlyPad(readonlyId, retrievedPadObj.Id) if err != nil { println("Error removing read-only pad mapping") return @@ -494,13 +507,13 @@ func HandlePadDelete(client *Client, padDeleteMessage PadDelete) { println("Error removing all saved revisions " + err.Error()) return } - if err := padManager.RemovePad(retrievedPadObj.Id); err != nil { + if err := p.padManager.RemovePad(retrievedPadObj.Id); err != nil { println("Error removing pad " + err.Error()) return } } -func HandleUserInfoUpdate(userInfo UserInfoUpdate, client *Client) { +func (p *PadMessageHandler) HandleUserInfoUpdate(userInfo UserInfoUpdate, client *Client) { if userInfo.Data.UserInfo.ColorId == nil { return } @@ -522,14 +535,14 @@ func HandleUserInfoUpdate(userInfo UserInfoUpdate, client *Client) { } if userInfo.Data.UserInfo.ColorId != nil { - authorManager.SetAuthorColor(session.Author, *userInfo.Data.UserInfo.ColorId) + p.authorManager.SetAuthorColor(session.Author, *userInfo.Data.UserInfo.ColorId) } if userInfo.Data.UserInfo.Name != nil { - authorManager.SetAuthorName(session.Author, *userInfo.Data.UserInfo.Name) + p.authorManager.SetAuthorName(session.Author, *userInfo.Data.UserInfo.Name) } var padId = session.PadId - var padSockets = GetRoomSockets(padId) + var padSockets = p.GetRoomSockets(padId) var userNewInfoDat = ws.UserNewInfoDat{ UserId: session.Author, @@ -559,7 +572,7 @@ func HandleUserInfoUpdate(userInfo UserInfoUpdate, client *Client) { } -func correctMarkersInPad(atext apool.AText, apool apool.APool) *string { +func (p *PadMessageHandler) correctMarkersInPad(atext apool.AText, apool apool.APool) *string { var text = atext.Text // collect char positions of line markers (e.g. bullets) in new atext @@ -604,7 +617,7 @@ func correctMarkersInPad(atext apool.AText, apool apool.APool) *string { return &stringifierBuilder } -func HandleDisconnectOfPadClient(client *Client, settings *settings.Settings, logger *zap.SugaredLogger) { +func (p *PadMessageHandler) HandleDisconnectOfPadClient(client *Client, settings *settings.Settings, logger *zap.SugaredLogger) { var thisSession = SessionStoreInstance.getSession(client.SessionId) if thisSession == nil || thisSession.PadId == "" { SessionStoreInstance.removeSession(client.SessionId) @@ -617,8 +630,8 @@ func HandleDisconnectOfPadClient(client *Client, settings *settings.Settings, lo logger.Infof("[LEAVE] pad:%s socket:%s IP:%s ", thisSession.PadId, client.SessionId, client.ctx.IP()) } - var roomSockets = GetRoomSockets(thisSession.PadId) - var authorToRemove, err = authorManager.GetAuthor(thisSession.Author) + var roomSockets = p.GetRoomSockets(thisSession.PadId) + var authorToRemove, err = p.authorManager.GetAuthor(thisSession.Author) if err != nil { println("Error retrieving author for disconnect") return @@ -657,21 +670,21 @@ func HandleDisconnectOfPadClient(client *Client, settings *settings.Settings, lo SessionStoreInstance.removeSession(client.SessionId) } -func HandleClientReadyMessage(ready ws.ClientReady, client *Client, thisSession *ws.Session, retrievedSettings *settings.Settings, logger *zap.SugaredLogger) { +func (p *PadMessageHandler) HandleClientReadyMessage(ready ws.ClientReady, client *Client, thisSession *ws.Session, retrievedSettings *settings.Settings, logger *zap.SugaredLogger) { if ready.Data.UserInfo.ColorId != nil && !colorRegEx.MatchString(*ready.Data.UserInfo.ColorId) { println("Invalid color id") ready.Data.UserInfo.ColorId = nil } if ready.Data.UserInfo.Name != nil { - authorManager.SetAuthorName(thisSession.Author, *ready.Data.UserInfo.Name) + p.authorManager.SetAuthorName(thisSession.Author, *ready.Data.UserInfo.Name) } if ready.Data.UserInfo.ColorId != nil { - authorManager.SetAuthorColor(thisSession.Author, *ready.Data.UserInfo.ColorId) + p.authorManager.SetAuthorColor(thisSession.Author, *ready.Data.UserInfo.ColorId) } - var retrievedPad, err = padManager.GetPad(thisSession.PadId, nil, &thisSession.Author) + var retrievedPad, err = p.padManager.GetPad(thisSession.PadId, nil, &thisSession.Author) if err != nil { println("Error getting pad") @@ -695,7 +708,7 @@ func HandleClientReadyMessage(ready ws.ClientReady, client *Client, thisSession logger.Infof(loggerStr, argsForLogger...) - var foundAuthor, errAuth = authorManager.GetAuthor(thisSession.Author) + var foundAuthor, errAuth = p.authorManager.GetAuthor(thisSession.Author) if errAuth != nil { println("Error retrieving author") @@ -714,7 +727,7 @@ func HandleClientReadyMessage(ready ws.ClientReady, client *Client, thisSession var historicalAuthorData = make(map[string]author.Author) for _, a := range authors { - var retrievedAuthor, err = authorManager.GetAuthor(a) + var retrievedAuthor, err = p.authorManager.GetAuthor(a) if err != nil { continue @@ -723,7 +736,7 @@ func HandleClientReadyMessage(ready ws.ClientReady, client *Client, thisSession historicalAuthorData[a] = *retrievedAuthor } - var roomSockets = GetRoomSockets(thisSession.PadId) + var roomSockets = p.GetRoomSockets(thisSession.PadId) for _, otherSocket := range roomSockets { if otherSocket.SessionId == client.SessionId { @@ -754,7 +767,7 @@ func HandleClientReadyMessage(ready ws.ClientReady, client *Client, thisSession var arr = make([]interface{}, 2) arr[0] = "message" arr[1] = Message{ - Data: clientVars.NewClientVars(*retrievedPad, thisSession, wirePool, historicalAuthorData, retrievedSettings), + Data: p.factory.NewClientVars(*retrievedPad, thisSession, wirePool, historicalAuthorData, retrievedSettings), Type: "CLIENT_VARS", } var encoded, _ = json.Marshal(arr) @@ -766,7 +779,7 @@ func HandleClientReadyMessage(ready ws.ClientReady, client *Client, thisSession thisSession.Revision = retrievedPad.Head } - retrievedAuthor, err := authorManager.GetAuthor(thisSession.Author) + retrievedAuthor, err := p.authorManager.GetAuthor(thisSession.Author) if err != nil { println("Error retrieving author for USER_NEWINFO broadcast") return @@ -806,7 +819,7 @@ func HandleClientReadyMessage(ready ws.ClientReady, client *Client, thisSession continue } var sinfo = SessionStoreInstance.getSession(socket.SessionId) - otherAuthor, err := authorManager.GetAuthor(sinfo.Author) + otherAuthor, err := p.authorManager.GetAuthor(sinfo.Author) if err != nil { println("Error retrieving author for USER_NEWINFO send to new client") continue @@ -837,8 +850,8 @@ func HandleClientReadyMessage(ready ws.ClientReady, client *Client, thisSession } } -func UpdatePadClients(pad *pad2.Pad) { - var roomSockets = GetRoomSockets(pad.Id) +func (p *PadMessageHandler) UpdatePadClients(pad *pad2.Pad) { + var roomSockets = p.GetRoomSockets(pad.Id) if len(roomSockets) == 0 { return } @@ -893,7 +906,7 @@ func UpdatePadClients(pad *pad2.Pad) { } } -func GetRoomSockets(padID string) []Client { +func (p *PadMessageHandler) GetRoomSockets(padID string) []Client { var sockets = make([]Client, 0) for k := range HubGlob.clients { if SessionStoreInstance.getSession(k.SessionId).PadId == padID { @@ -903,7 +916,7 @@ func GetRoomSockets(padID string) []Client { return sockets } -func KickSessionsFromPad(padID string) { +func (p *PadMessageHandler) KickSessionsFromPad(padID string) { for k := range HubGlob.clients { if SessionStoreInstance.getSession(k.SessionId).PadId == padID { k.SendPadDelete() diff --git a/lib/ws/client.go b/lib/ws/client.go index 851ef484..aafbeba1 100644 --- a/lib/ws/client.go +++ b/lib/ws/client.go @@ -46,6 +46,7 @@ type Client struct { Room string SessionId string ctx *fiber.Ctx + handler *PadMessageHandler } func (c *Client) readPumpAdmin(retrievedSettings *settings.Settings, logger *zap.SugaredLogger) { @@ -62,7 +63,7 @@ func (c *Client) readPumpAdmin(retrievedSettings *settings.Settings, logger *zap if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) { log.Printf("error: %v", err) } - HandleDisconnectOfPadClient(c, retrievedSettings, logger) + c.handler.HandleDisconnectOfPadClient(c, retrievedSettings, logger) break } message = bytes.TrimSpace(bytes.Replace(message, newline, space, -1)) @@ -90,7 +91,7 @@ func (c *Client) readPump(retrievedSettings *settings.Settings, logger *zap.Suga if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) { log.Printf("error: %v", err) } - HandleDisconnectOfPadClient(c, retrievedSettings, logger) + c.handler.HandleDisconnectOfPadClient(c, retrievedSettings, logger) break } if err := ratelimiter.CheckRateLimit(ratelimiter.IPAddress(c.ctx.IP()), retrievedSettings.CommitRateLimiting); err != nil { @@ -107,7 +108,7 @@ func (c *Client) readPump(retrievedSettings *settings.Settings, logger *zap.Suga println("Error unmarshalling", err) } - handleMessage(clientReady, c, c.ctx, retrievedSettings, logger) + c.handler.handleMessage(clientReady, c, c.ctx, retrievedSettings, logger) } else if strings.Contains(decodedMessage, "USER_CHANGES") { var userchange ws.UserChange err := json.Unmarshal(message, &userchange) @@ -117,7 +118,7 @@ func (c *Client) readPump(retrievedSettings *settings.Settings, logger *zap.Suga return } - handleMessage(userchange, c, c.ctx, retrievedSettings, logger) + c.handler.handleMessage(userchange, c, c.ctx, retrievedSettings, logger) } else if strings.Contains(decodedMessage, "USERINFO_UPDATE") { var userInfoChange UserInfoUpdateWrapper errorUserInfoChange := json.Unmarshal(message, &userInfoChange) @@ -127,7 +128,7 @@ func (c *Client) readPump(retrievedSettings *settings.Settings, logger *zap.Suga return } - handleMessage(userInfoChange.Data, c, c.ctx, retrievedSettings, logger) + c.handler.handleMessage(userInfoChange.Data, c, c.ctx, retrievedSettings, logger) } else if strings.Contains(decodedMessage, "GET_CHAT_MESSAGES") { var getChatMessages ws.GetChatMessages err := json.Unmarshal(message, &getChatMessages) @@ -137,7 +138,7 @@ func (c *Client) readPump(retrievedSettings *settings.Settings, logger *zap.Suga return } - handleMessage(getChatMessages, c, c.ctx, retrievedSettings, logger) + c.handler.handleMessage(getChatMessages, c, c.ctx, retrievedSettings, logger) } else if strings.Contains(decodedMessage, "CHAT_MESSAGE") { var chatMessage ws.ChatMessage @@ -146,7 +147,7 @@ func (c *Client) readPump(retrievedSettings *settings.Settings, logger *zap.Suga if err != nil { logger.Error("Error unmarshalling", err) } - handleMessage(chatMessage, c, c.ctx, retrievedSettings, logger) + c.handler.handleMessage(chatMessage, c, c.ctx, retrievedSettings, logger) } c.hub.Broadcast <- message @@ -166,7 +167,9 @@ func (c *Client) SendPadDelete() { } // ServeWs serveWs handles websocket requests from the peer. -func ServeWs(hub *Hub, w http.ResponseWriter, r *http.Request, sessionStore *session.Store, fiber *fiber.Ctx, configSettings *settings.Settings, logger *zap.SugaredLogger) { +func ServeWs(hub *Hub, w http.ResponseWriter, r *http.Request, sessionStore *session.Store, + fiber *fiber.Ctx, configSettings *settings.Settings, + logger *zap.SugaredLogger, handler *PadMessageHandler) { store, err := sessionStore.Get(fiber) if err != nil { @@ -178,7 +181,7 @@ func ServeWs(hub *Hub, w http.ResponseWriter, r *http.Request, sessionStore *ses log.Println(err) return } - client := &Client{hub: hub, conn: conn, Send: make(chan []byte, 256), SessionId: store.ID(), ctx: fiber} + client := &Client{hub: hub, conn: conn, Send: make(chan []byte, 256), SessionId: store.ID(), ctx: fiber, handler: handler} SessionStoreInstance.initSession(store.ID()) client.hub.Register <- client client.readPump(configSettings, logger) diff --git a/main.go b/main.go index 55b2a015..8be8cd6d 100644 --- a/main.go +++ b/main.go @@ -69,13 +69,16 @@ func main() { setupLogger.Info("Report bugs at https://github.com/ether/etherpad-go/issues") setupLogger.Info("Your Etherpad Go version is " + settings2.GetGitCommit()) + dataStore, err := utils.GetDB(settings) + readOnlyManager := pad.NewReadOnlyManager(dataStore) + var db = session2.NewSessionDatabase(nil) app := fiber.New(fiber.Config{ DisableStartupMessage: true, }) app.Use(func(c *fiber.Ctx) error { - return pad.CheckAccess(c, setupLogger, &settings) + return pad.CheckAccess(c, setupLogger, &settings, readOnlyManager) }) var cookieStore = session.New(session.Config{ @@ -88,9 +91,16 @@ func main() { hooks.ExpressPreSession(app, uiAssets) ws.HubGlob = ws.NewHub() go ws.HubGlob.Run() + + if err != nil { + setupLogger.Fatal("Error connecting to database: " + err.Error()) + return + } + + padMessageHandler := ws.NewPadMessageHandler(dataStore) app.Get("/socket.io/*", func(c *fiber.Ctx) error { return adaptor.HTTPHandlerFunc(func(writer http.ResponseWriter, request *http.Request) { - ws.ServeWs(ws.HubGlob, writer, request, cookieStore, c, &settings, setupLogger) + ws.ServeWs(ws.HubGlob, writer, request, cookieStore, c, &settings, setupLogger, padMessageHandler) })(c) }) app.Get("/admin/ws", func(c *fiber.Ctx) error { @@ -99,11 +109,11 @@ func main() { })(c) }) - api2.InitAPI(app, uiAssets, settings, cookieStore) + api2.InitAPI(app, uiAssets, settings, cookieStore, dataStore, padMessageHandler) fiberString := fmt.Sprintf("%s:%s", settings.IP, settings.Port) setupLogger.Info("Starting Web UI on " + fiberString) - err := app.Listen(fiberString) + err = app.Listen(fiberString) if err != nil { return } diff --git a/var/.gitkeep b/var/.gitkeep new file mode 100644 index 00000000..e69de29b From aeb1c36889015874caf5cf5b3c405e3d8be148fc Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+samtv12345@users.noreply.github.com> Date: Wed, 12 Nov 2025 20:36:05 +0100 Subject: [PATCH 2/2] chore: fixed pong interval of websocket --- lib/ws/client.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/ws/client.go b/lib/ws/client.go index aafbeba1..d17db9ff 100644 --- a/lib/ws/client.go +++ b/lib/ws/client.go @@ -10,7 +10,6 @@ import ( "log" "net/http" "strings" - "time" "github.com/ether/etherpad-go/lib/models/ws" "github.com/ether/etherpad-go/lib/settings" @@ -22,10 +21,6 @@ import ( "github.com/gorilla/websocket" ) -const ( - pongWait = 60 * time.Second -) - var upgrader = websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, @@ -55,8 +50,6 @@ func (c *Client) readPumpAdmin(retrievedSettings *settings.Settings, logger *zap c.conn.Close() }() c.conn.SetReadLimit(retrievedSettings.SocketIo.MaxHttpBufferSize) - c.conn.SetReadDeadline(time.Now().Add(pongWait)) - c.conn.SetPongHandler(func(string) error { c.conn.SetReadDeadline(time.Now().Add(pongWait)); return nil }) for { _, message, err := c.conn.ReadMessage() if err != nil { @@ -83,8 +76,6 @@ func (c *Client) readPump(retrievedSettings *settings.Settings, logger *zap.Suga c.conn.Close() }() c.conn.SetReadLimit(retrievedSettings.SocketIo.MaxHttpBufferSize) - c.conn.SetReadDeadline(time.Now().Add(pongWait)) - c.conn.SetPongHandler(func(string) error { c.conn.SetReadDeadline(time.Now().Add(pongWait)); return nil }) for { _, message, err := c.conn.ReadMessage() if err != nil {