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: "*",
|
||||
username: "~u",
|
||||
caps: xirc.NewCapRegistry(),
|
||||
monitored: newCasemapMap[struct{}](),
|
||||
monitored: newCasemapMap[struct{}](xirc.CaseMappingASCII),
|
||||
registration: new(downstreamRegistration),
|
||||
}
|
||||
dc.monitored.SetCaseMapping(xirc.CaseMappingASCII)
|
||||
if host, _, err := net.SplitHostPort(remoteAddr); err == nil {
|
||||
dc.hostname = host
|
||||
} else {
|
||||
@ -2651,8 +2650,7 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
|
||||
}
|
||||
uc.updateMonitor()
|
||||
case "C": // clear
|
||||
dc.monitored = newCasemapMap[struct{}]()
|
||||
dc.monitored.SetCaseMapping(uc.network.casemap)
|
||||
dc.monitored = newCasemapMap[struct{}](uc.network.casemap)
|
||||
uc.updateMonitor()
|
||||
case "L": // 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
|
||||
}
|
||||
|
||||
func newCasemapMap[V interface{}]() casemapMap[V] {
|
||||
func newCasemapMap[V interface{}](cm xirc.CaseMapping) casemapMap[V] {
|
||||
return casemapMap[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,
|
||||
}
|
||||
|
||||
cm := stdCaseMapping
|
||||
uc := &upstreamConn{
|
||||
conn: *newConn(network.user.srv, newNetIRCConn(netConn), &options),
|
||||
network: network,
|
||||
user: network.user,
|
||||
channels: newCasemapMap[*upstreamChannel](),
|
||||
users: newCasemapMap[*upstreamUser](),
|
||||
channels: newCasemapMap[*upstreamChannel](cm),
|
||||
users: newCasemapMap[*upstreamUser](cm),
|
||||
caps: xirc.NewCapRegistry(),
|
||||
batches: make(map[string]upstreamBatch),
|
||||
serverPrefix: &irc.Prefix{Name: "*"},
|
||||
@ -376,7 +377,7 @@ func connectToUpstream(ctx context.Context, network *network) (*upstreamConn, er
|
||||
availableMemberships: stdMemberships,
|
||||
isupport: make(map[string]*string),
|
||||
pendingCmds: make(map[string][]pendingUpstreamCommand),
|
||||
monitored: newCasemapMap[bool](),
|
||||
monitored: newCasemapMap[bool](cm),
|
||||
hasDesiredNick: true,
|
||||
}
|
||||
return uc, nil
|
||||
@ -1173,8 +1174,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
|
||||
for _, ch := range strings.Split(channels, ",") {
|
||||
if uc.isOurNick(msg.Prefix.Name) {
|
||||
uc.logger.Printf("joined channel %q", ch)
|
||||
members := newCasemapMap[*xirc.MembershipSet]()
|
||||
members.casemap = uc.network.casemap
|
||||
members := newCasemapMap[*xirc.MembershipSet](uc.network.casemap)
|
||||
uc.channels.Set(ch, &upstreamChannel{
|
||||
Name: ch,
|
||||
conn: uc,
|
||||
|
14
user.go
14
user.go
@ -96,8 +96,8 @@ type deliveredStore struct {
|
||||
m casemapMap[deliveredClientMap]
|
||||
}
|
||||
|
||||
func newDeliveredStore() deliveredStore {
|
||||
return deliveredStore{newCasemapMap[deliveredClientMap]()}
|
||||
func newDeliveredStore(cm xirc.CaseMapping) deliveredStore {
|
||||
return deliveredStore{newCasemapMap[deliveredClientMap](cm)}
|
||||
}
|
||||
|
||||
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 {
|
||||
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 {
|
||||
ch := ch
|
||||
m.Set(ch.Name, &ch)
|
||||
@ -169,8 +173,8 @@ func newNetwork(user *user, record *database.Network, channels []database.Channe
|
||||
logger: logger,
|
||||
stopped: make(chan struct{}),
|
||||
channels: m,
|
||||
delivered: newDeliveredStore(),
|
||||
pushTargets: newCasemapMap[time.Time](),
|
||||
delivered: newDeliveredStore(cm),
|
||||
pushTargets: newCasemapMap[time.Time](cm),
|
||||
casemap: stdCaseMapping,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user