mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-29 07:29:31 +01:00
load isupport directly into the config object
eliminates Server.configurableStateMutex
This commit is contained in:
parent
61d666a25b
commit
ce6a3e42df
@ -836,7 +836,8 @@ func (client *Client) LoggedIntoAccount() bool {
|
||||
func (client *Client) RplISupport(rb *ResponseBuffer) {
|
||||
translatedISupport := client.t("are supported by this server")
|
||||
nick := client.Nick()
|
||||
for _, cachedTokenLine := range client.server.ISupport().CachedReply {
|
||||
config := client.server.Config()
|
||||
for _, cachedTokenLine := range config.Server.isupport.CachedReply {
|
||||
length := len(cachedTokenLine) + 2
|
||||
tokenline := make([]string, length)
|
||||
tokenline[0] = nick
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"code.cloudfoundry.org/bytefmt"
|
||||
"github.com/oragono/oragono/irc/connection_limits"
|
||||
"github.com/oragono/oragono/irc/custime"
|
||||
"github.com/oragono/oragono/irc/isupport"
|
||||
"github.com/oragono/oragono/irc/languages"
|
||||
"github.com/oragono/oragono/irc/logger"
|
||||
"github.com/oragono/oragono/irc/modes"
|
||||
@ -293,6 +294,7 @@ type Config struct {
|
||||
forceTrailing bool
|
||||
SendUnprefixedSasl bool `yaml:"send-unprefixed-sasl"`
|
||||
}
|
||||
isupport isupport.List
|
||||
ConnectionLimiter connection_limits.LimiterConfig `yaml:"connection-limits"`
|
||||
ConnectionThrottler connection_limits.ThrottlerConfig `yaml:"connection-throttling"`
|
||||
}
|
||||
@ -713,6 +715,11 @@ func LoadConfig(filename string) (config *Config, err error) {
|
||||
|
||||
config.loadMOTD()
|
||||
|
||||
err = config.generateISupport()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// in the current implementation, we disable history by creating a history buffer
|
||||
// with zero capacity. but the `enabled` config option MUST be respected regardless
|
||||
// of this detail
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/oragono/oragono/irc/isupport"
|
||||
"github.com/oragono/oragono/irc/languages"
|
||||
"github.com/oragono/oragono/irc/modes"
|
||||
)
|
||||
@ -21,12 +20,6 @@ func (server *Server) SetConfig(config *Config) {
|
||||
atomic.StorePointer(&server.config, unsafe.Pointer(config))
|
||||
}
|
||||
|
||||
func (server *Server) ISupport() *isupport.List {
|
||||
server.configurableStateMutex.RLock()
|
||||
defer server.configurableStateMutex.RUnlock()
|
||||
return server.isupport
|
||||
}
|
||||
|
||||
func (server *Server) Limits() Limits {
|
||||
return server.Config().Limits
|
||||
}
|
||||
|
@ -22,9 +22,13 @@ type List struct {
|
||||
// NewList returns a new List
|
||||
func NewList() *List {
|
||||
var il List
|
||||
il.Initialize()
|
||||
return &il
|
||||
}
|
||||
|
||||
func (il *List) Initialize() {
|
||||
il.Tokens = make(map[string]*string)
|
||||
il.CachedReply = make([][]string, 0)
|
||||
return &il
|
||||
}
|
||||
|
||||
// Add adds an RPL_ISUPPORT token to our internal list
|
||||
|
@ -62,37 +62,36 @@ type ListenerWrapper struct {
|
||||
|
||||
// Server is the main Oragono server.
|
||||
type Server struct {
|
||||
accounts AccountManager
|
||||
channels ChannelManager
|
||||
channelRegistry ChannelRegistry
|
||||
clients ClientManager
|
||||
config unsafe.Pointer
|
||||
configFilename string
|
||||
configurableStateMutex sync.RWMutex // tier 1; generic protection for server state modified by rehash()
|
||||
connectionLimiter *connection_limits.Limiter
|
||||
connectionThrottler *connection_limits.Throttler
|
||||
ctime time.Time
|
||||
dlines *DLineManager
|
||||
helpIndexManager HelpIndexManager
|
||||
isupport *isupport.List
|
||||
klines *KLineManager
|
||||
listeners map[string]*ListenerWrapper
|
||||
logger *logger.Manager
|
||||
monitorManager *MonitorManager
|
||||
motdLines []string
|
||||
name string
|
||||
nameCasefolded string
|
||||
rehashMutex sync.Mutex // tier 4
|
||||
rehashSignal chan os.Signal
|
||||
pprofServer *http.Server
|
||||
resumeManager ResumeManager
|
||||
signals chan os.Signal
|
||||
snomasks *SnoManager
|
||||
store *buntdb.DB
|
||||
torLimiter connection_limits.TorLimiter
|
||||
whoWas WhoWasList
|
||||
stats Stats
|
||||
semaphores ServerSemaphores
|
||||
accounts AccountManager
|
||||
channels ChannelManager
|
||||
channelRegistry ChannelRegistry
|
||||
clients ClientManager
|
||||
config unsafe.Pointer
|
||||
configFilename string
|
||||
connectionLimiter *connection_limits.Limiter
|
||||
connectionThrottler *connection_limits.Throttler
|
||||
ctime time.Time
|
||||
dlines *DLineManager
|
||||
helpIndexManager HelpIndexManager
|
||||
isupport *isupport.List
|
||||
klines *KLineManager
|
||||
listeners map[string]*ListenerWrapper
|
||||
logger *logger.Manager
|
||||
monitorManager *MonitorManager
|
||||
motdLines []string
|
||||
name string
|
||||
nameCasefolded string
|
||||
rehashMutex sync.Mutex // tier 4
|
||||
rehashSignal chan os.Signal
|
||||
pprofServer *http.Server
|
||||
resumeManager ResumeManager
|
||||
signals chan os.Signal
|
||||
snomasks *SnoManager
|
||||
store *buntdb.DB
|
||||
torLimiter connection_limits.TorLimiter
|
||||
whoWas WhoWasList
|
||||
stats Stats
|
||||
semaphores ServerSemaphores
|
||||
}
|
||||
|
||||
var (
|
||||
@ -141,13 +140,12 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
|
||||
}
|
||||
|
||||
// setISupport sets up our RPL_ISUPPORT reply.
|
||||
func (server *Server) setISupport() (err error) {
|
||||
func (config *Config) generateISupport() (err error) {
|
||||
maxTargetsString := strconv.Itoa(maxTargets)
|
||||
|
||||
config := server.Config()
|
||||
|
||||
// add RPL_ISUPPORT tokens
|
||||
isupport := isupport.NewList()
|
||||
isupport := &config.Server.isupport
|
||||
isupport.Initialize()
|
||||
isupport.Add("AWAYLEN", strconv.Itoa(config.Limits.AwayLen))
|
||||
isupport.Add("CASEMAPPING", "ascii")
|
||||
isupport.Add("CHANMODES", strings.Join([]string{modes.Modes{modes.BanMask, modes.ExceptMask, modes.InviteMask}.String(), "", modes.Modes{modes.UserLimit, modes.Key}.String(), modes.Modes{modes.InviteOnly, modes.Moderated, modes.NoOutside, modes.OpOnlyTopic, modes.ChanRoleplaying, modes.Secret}.String()}, ","))
|
||||
@ -175,13 +173,6 @@ func (server *Server) setISupport() (err error) {
|
||||
isupport.Add("UTF8MAPPING", casemappingName)
|
||||
|
||||
err = isupport.RegenerateCachedReply()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
server.configurableStateMutex.Lock()
|
||||
server.isupport = isupport
|
||||
server.configurableStateMutex.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
@ -786,13 +777,8 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) {
|
||||
|
||||
// set RPL_ISUPPORT
|
||||
var newISupportReplies [][]string
|
||||
oldISupportList := server.ISupport()
|
||||
err = server.setISupport()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if oldISupportList != nil {
|
||||
newISupportReplies = oldISupportList.GetDifference(server.ISupport())
|
||||
if oldConfig != nil {
|
||||
newISupportReplies = oldConfig.Server.isupport.GetDifference(&config.Server.isupport)
|
||||
}
|
||||
|
||||
// we are now open for business
|
||||
|
Loading…
Reference in New Issue
Block a user