Reduce raciness

This commit is contained in:
kayos@tcp.direct 2022-03-19 20:59:13 -07:00
parent f6902689f1
commit e835e5898d
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
3 changed files with 13 additions and 9 deletions

@ -112,7 +112,7 @@ func handleConnect(c *Client, e Event) {
if len(split) < i {
break search
}
c.IRCd.Network = split[i+1]
c.IRCd.Network.Store(split[i+1])
break search
default:
break search
@ -515,7 +515,7 @@ func handleISUPPORT(c *Client, e Event) {
}
if split[0] == "NETWORK" {
c.state.network = split[1]
c.state.network.Store(split[1])
}
c.state.serverOptions.Set(split[0], split[1])

@ -70,7 +70,7 @@ type Client struct {
// Server contains information about the IRC server that the client is connected to.
type Server struct {
// Network is the name of the IRC network we are connected to as acquired by 001.
Network string
Network atomic.Value
// Version is the software version of the IRC daemon as acquired by 004.
Version string
// Host is the hostname/id/IP of the leaf, as acquired by 002.
@ -299,11 +299,14 @@ func New(config Config) *Client {
}
c.IRCd = Server{
Network: atomic.Value{},
Version: "",
UserCount: 0,
MaxUserCount: 0,
}
c.IRCd.Network.Store("")
c.Cmd = &Commands{c: c}
if c.Config.PingDelay >= 0 && c.Config.PingDelay < (20*time.Second) {
@ -734,17 +737,17 @@ func (c *Client) NetworkName() (name string) {
c.panicIfNotTracking()
var ok bool
if len(c.state.network) > 0 {
return c.state.network
if len(c.state.network.Load().(string)) > 0 {
return c.state.network.Load().(string)
}
name, ok = c.GetServerOpt("NETWORK")
if !ok {
return c.IRCd.Network
return c.IRCd.Network.Load().(string)
}
if len(name) < 1 && len(c.IRCd.Network) > 1 {
name = c.IRCd.Network
if len(name) < 1 && len(c.IRCd.Network.Load().(string)) > 1 {
name = c.IRCd.Network.Load().(string)
}
return name

@ -39,7 +39,7 @@ type state struct {
serverOptions cmap.ConcurrentMap
// network is an alternative way to store and retrieve the NETWORK server option.
network string
network atomic.Value
// motd is the servers message of the day.
motd string
@ -60,6 +60,7 @@ func (s *state) reset(initial bool) {
s.nick.Store("")
s.ident.Store("")
s.host.Store("")
s.network.Store("")
var cmaps = []*cmap.ConcurrentMap{&s.channels, &s.users, &s.serverOptions}
for _, cm := range cmaps {
if initial {