3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

load isupport directly into the config object

eliminates Server.configurableStateMutex
This commit is contained in:
Shivaram Lingamneni 2019-05-10 00:27:28 -04:00
parent 61d666a25b
commit ce6a3e42df
5 changed files with 49 additions and 58 deletions

View File

@ -836,7 +836,8 @@ func (client *Client) LoggedIntoAccount() bool {
func (client *Client) RplISupport(rb *ResponseBuffer) { func (client *Client) RplISupport(rb *ResponseBuffer) {
translatedISupport := client.t("are supported by this server") translatedISupport := client.t("are supported by this server")
nick := client.Nick() 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 length := len(cachedTokenLine) + 2
tokenline := make([]string, length) tokenline := make([]string, length)
tokenline[0] = nick tokenline[0] = nick

View File

@ -20,6 +20,7 @@ import (
"code.cloudfoundry.org/bytefmt" "code.cloudfoundry.org/bytefmt"
"github.com/oragono/oragono/irc/connection_limits" "github.com/oragono/oragono/irc/connection_limits"
"github.com/oragono/oragono/irc/custime" "github.com/oragono/oragono/irc/custime"
"github.com/oragono/oragono/irc/isupport"
"github.com/oragono/oragono/irc/languages" "github.com/oragono/oragono/irc/languages"
"github.com/oragono/oragono/irc/logger" "github.com/oragono/oragono/irc/logger"
"github.com/oragono/oragono/irc/modes" "github.com/oragono/oragono/irc/modes"
@ -293,6 +294,7 @@ type Config struct {
forceTrailing bool forceTrailing bool
SendUnprefixedSasl bool `yaml:"send-unprefixed-sasl"` SendUnprefixedSasl bool `yaml:"send-unprefixed-sasl"`
} }
isupport isupport.List
ConnectionLimiter connection_limits.LimiterConfig `yaml:"connection-limits"` ConnectionLimiter connection_limits.LimiterConfig `yaml:"connection-limits"`
ConnectionThrottler connection_limits.ThrottlerConfig `yaml:"connection-throttling"` ConnectionThrottler connection_limits.ThrottlerConfig `yaml:"connection-throttling"`
} }
@ -713,6 +715,11 @@ func LoadConfig(filename string) (config *Config, err error) {
config.loadMOTD() config.loadMOTD()
err = config.generateISupport()
if err != nil {
return nil, err
}
// in the current implementation, we disable history by creating a history buffer // in the current implementation, we disable history by creating a history buffer
// with zero capacity. but the `enabled` config option MUST be respected regardless // with zero capacity. but the `enabled` config option MUST be respected regardless
// of this detail // of this detail

View File

@ -8,7 +8,6 @@ import (
"time" "time"
"unsafe" "unsafe"
"github.com/oragono/oragono/irc/isupport"
"github.com/oragono/oragono/irc/languages" "github.com/oragono/oragono/irc/languages"
"github.com/oragono/oragono/irc/modes" "github.com/oragono/oragono/irc/modes"
) )
@ -21,12 +20,6 @@ func (server *Server) SetConfig(config *Config) {
atomic.StorePointer(&server.config, unsafe.Pointer(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 { func (server *Server) Limits() Limits {
return server.Config().Limits return server.Config().Limits
} }

View File

@ -22,9 +22,13 @@ type List struct {
// NewList returns a new List // NewList returns a new List
func NewList() *List { func NewList() *List {
var il List var il List
il.Initialize()
return &il
}
func (il *List) Initialize() {
il.Tokens = make(map[string]*string) il.Tokens = make(map[string]*string)
il.CachedReply = make([][]string, 0) il.CachedReply = make([][]string, 0)
return &il
} }
// Add adds an RPL_ISUPPORT token to our internal list // Add adds an RPL_ISUPPORT token to our internal list

View File

@ -68,7 +68,6 @@ type Server struct {
clients ClientManager clients ClientManager
config unsafe.Pointer config unsafe.Pointer
configFilename string configFilename string
configurableStateMutex sync.RWMutex // tier 1; generic protection for server state modified by rehash()
connectionLimiter *connection_limits.Limiter connectionLimiter *connection_limits.Limiter
connectionThrottler *connection_limits.Throttler connectionThrottler *connection_limits.Throttler
ctime time.Time ctime time.Time
@ -141,13 +140,12 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
} }
// setISupport sets up our RPL_ISUPPORT reply. // setISupport sets up our RPL_ISUPPORT reply.
func (server *Server) setISupport() (err error) { func (config *Config) generateISupport() (err error) {
maxTargetsString := strconv.Itoa(maxTargets) maxTargetsString := strconv.Itoa(maxTargets)
config := server.Config()
// add RPL_ISUPPORT tokens // add RPL_ISUPPORT tokens
isupport := isupport.NewList() isupport := &config.Server.isupport
isupport.Initialize()
isupport.Add("AWAYLEN", strconv.Itoa(config.Limits.AwayLen)) isupport.Add("AWAYLEN", strconv.Itoa(config.Limits.AwayLen))
isupport.Add("CASEMAPPING", "ascii") 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()}, ",")) 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) isupport.Add("UTF8MAPPING", casemappingName)
err = isupport.RegenerateCachedReply() err = isupport.RegenerateCachedReply()
if err != nil {
return
}
server.configurableStateMutex.Lock()
server.isupport = isupport
server.configurableStateMutex.Unlock()
return return
} }
@ -786,13 +777,8 @@ func (server *Server) applyConfig(config *Config, initial bool) (err error) {
// set RPL_ISUPPORT // set RPL_ISUPPORT
var newISupportReplies [][]string var newISupportReplies [][]string
oldISupportList := server.ISupport() if oldConfig != nil {
err = server.setISupport() newISupportReplies = oldConfig.Server.isupport.GetDifference(&config.Server.isupport)
if err != nil {
return err
}
if oldISupportList != nil {
newISupportReplies = oldISupportList.GetDifference(server.ISupport())
} }
// we are now open for business // we are now open for business