Take case-mapping as param in newCasemapMap()
Avoids situations where we forget to initialize it.
This commit is contained in:
parent
de90648eaa
commit
2b7a83b676
@ -362,10 +362,9 @@ func newDownstreamConn(srv *Server, ic ircConn, id uint64) *downstreamConn {
|
|||||||
nickCM: "*",
|
nickCM: "*",
|
||||||
username: "~u",
|
username: "~u",
|
||||||
caps: xirc.NewCapRegistry(),
|
caps: xirc.NewCapRegistry(),
|
||||||
monitored: newCasemapMap[struct{}](),
|
monitored: newCasemapMap[struct{}](xirc.CaseMappingASCII),
|
||||||
registration: new(downstreamRegistration),
|
registration: new(downstreamRegistration),
|
||||||
}
|
}
|
||||||
dc.monitored.SetCaseMapping(xirc.CaseMappingASCII)
|
|
||||||
if host, _, err := net.SplitHostPort(remoteAddr); err == nil {
|
if host, _, err := net.SplitHostPort(remoteAddr); err == nil {
|
||||||
dc.hostname = host
|
dc.hostname = host
|
||||||
} else {
|
} else {
|
||||||
@ -2651,8 +2650,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
|
|||||||
}
|
}
|
||||||
uc.updateMonitor()
|
uc.updateMonitor()
|
||||||
case "C": // clear
|
case "C": // clear
|
||||||
dc.monitored = newCasemapMap[struct{}]()
|
dc.monitored = newCasemapMap[struct{}](uc.network.casemap)
|
||||||
dc.monitored.SetCaseMapping(uc.network.casemap)
|
|
||||||
uc.updateMonitor()
|
uc.updateMonitor()
|
||||||
case "L": // list
|
case "L": // list
|
||||||
// TODO: be less lazy and pack the list
|
// TODO: be less lazy and pack the list
|
||||||
|
4
irc.go
4
irc.go
@ -228,10 +228,10 @@ type casemapEntry[V interface{}] struct {
|
|||||||
value V
|
value V
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCasemapMap[V interface{}]() casemapMap[V] {
|
func newCasemapMap[V interface{}](cm xirc.CaseMapping) casemapMap[V] {
|
||||||
return casemapMap[V]{
|
return casemapMap[V]{
|
||||||
m: make(map[string]casemapEntry[V]),
|
m: make(map[string]casemapEntry[V]),
|
||||||
casemap: xirc.CaseMappingNone,
|
casemap: cm,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
upstream.go
10
upstream.go
@ -362,12 +362,13 @@ func connectToUpstream(ctx context.Context, network *network) (*upstreamConn, er
|
|||||||
RateLimitBurst: upstreamMessageBurst,
|
RateLimitBurst: upstreamMessageBurst,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cm := stdCaseMapping
|
||||||
uc := &upstreamConn{
|
uc := &upstreamConn{
|
||||||
conn: *newConn(network.user.srv, newNetIRCConn(netConn), &options),
|
conn: *newConn(network.user.srv, newNetIRCConn(netConn), &options),
|
||||||
network: network,
|
network: network,
|
||||||
user: network.user,
|
user: network.user,
|
||||||
channels: newCasemapMap[*upstreamChannel](),
|
channels: newCasemapMap[*upstreamChannel](cm),
|
||||||
users: newCasemapMap[*upstreamUser](),
|
users: newCasemapMap[*upstreamUser](cm),
|
||||||
caps: xirc.NewCapRegistry(),
|
caps: xirc.NewCapRegistry(),
|
||||||
batches: make(map[string]upstreamBatch),
|
batches: make(map[string]upstreamBatch),
|
||||||
serverPrefix: &irc.Prefix{Name: "*"},
|
serverPrefix: &irc.Prefix{Name: "*"},
|
||||||
@ -376,7 +377,7 @@ func connectToUpstream(ctx context.Context, network *network) (*upstreamConn, er
|
|||||||
availableMemberships: stdMemberships,
|
availableMemberships: stdMemberships,
|
||||||
isupport: make(map[string]*string),
|
isupport: make(map[string]*string),
|
||||||
pendingCmds: make(map[string][]pendingUpstreamCommand),
|
pendingCmds: make(map[string][]pendingUpstreamCommand),
|
||||||
monitored: newCasemapMap[bool](),
|
monitored: newCasemapMap[bool](cm),
|
||||||
hasDesiredNick: true,
|
hasDesiredNick: true,
|
||||||
}
|
}
|
||||||
return uc, nil
|
return uc, nil
|
||||||
@ -1173,8 +1174,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
|
|||||||
for _, ch := range strings.Split(channels, ",") {
|
for _, ch := range strings.Split(channels, ",") {
|
||||||
if uc.isOurNick(msg.Prefix.Name) {
|
if uc.isOurNick(msg.Prefix.Name) {
|
||||||
uc.logger.Printf("joined channel %q", ch)
|
uc.logger.Printf("joined channel %q", ch)
|
||||||
members := newCasemapMap[*xirc.MembershipSet]()
|
members := newCasemapMap[*xirc.MembershipSet](uc.network.casemap)
|
||||||
members.casemap = uc.network.casemap
|
|
||||||
uc.channels.Set(ch, &upstreamChannel{
|
uc.channels.Set(ch, &upstreamChannel{
|
||||||
Name: ch,
|
Name: ch,
|
||||||
conn: uc,
|
conn: uc,
|
||||||
|
14
user.go
14
user.go
@ -96,8 +96,8 @@ type deliveredStore struct {
|
|||||||
m casemapMap[deliveredClientMap]
|
m casemapMap[deliveredClientMap]
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDeliveredStore() deliveredStore {
|
func newDeliveredStore(cm xirc.CaseMapping) deliveredStore {
|
||||||
return deliveredStore{newCasemapMap[deliveredClientMap]()}
|
return deliveredStore{newCasemapMap[deliveredClientMap](cm)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds deliveredStore) HasTarget(target string) bool {
|
func (ds deliveredStore) HasTarget(target string) bool {
|
||||||
@ -157,7 +157,11 @@ type network struct {
|
|||||||
func newNetwork(user *user, record *database.Network, channels []database.Channel) *network {
|
func newNetwork(user *user, record *database.Network, channels []database.Channel) *network {
|
||||||
logger := &prefixLogger{user.logger, fmt.Sprintf("network %q: ", record.GetName())}
|
logger := &prefixLogger{user.logger, fmt.Sprintf("network %q: ", record.GetName())}
|
||||||
|
|
||||||
m := newCasemapMap[*database.Channel]()
|
// Initialize maps with the no-op case-mapping to avoid collisions: we
|
||||||
|
// don't know which case-mapping will be used by the upstream server yet
|
||||||
|
cm := xirc.CaseMappingNone
|
||||||
|
|
||||||
|
m := newCasemapMap[*database.Channel](cm)
|
||||||
for _, ch := range channels {
|
for _, ch := range channels {
|
||||||
ch := ch
|
ch := ch
|
||||||
m.Set(ch.Name, &ch)
|
m.Set(ch.Name, &ch)
|
||||||
@ -169,8 +173,8 @@ func newNetwork(user *user, record *database.Network, channels []database.Channe
|
|||||||
logger: logger,
|
logger: logger,
|
||||||
stopped: make(chan struct{}),
|
stopped: make(chan struct{}),
|
||||||
channels: m,
|
channels: m,
|
||||||
delivered: newDeliveredStore(),
|
delivered: newDeliveredStore(cm),
|
||||||
pushTargets: newCasemapMap[time.Time](),
|
pushTargets: newCasemapMap[time.Time](cm),
|
||||||
casemap: stdCaseMapping,
|
casemap: stdCaseMapping,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user