Remove downstreamConn.ringConsumers

We no longer need long-lived ring buffer consumers now that
upstreamConn.produce dispatches messages to downstream connections.
This commit is contained in:
Simon Ser 2020-04-06 18:31:48 +02:00
parent 40ff14ec6c
commit f0bc919885
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
4 changed files with 12 additions and 18 deletions

View File

@ -66,7 +66,6 @@ type downstreamConn struct {
password string // empty after authentication
network *network // can be nil
ringConsumers map[*network]*RingConsumer
ourMessages map[*irc.Message]struct{}
caps map[string]bool
@ -81,7 +80,6 @@ func newDownstreamConn(srv *Server, netConn net.Conn, id uint64) *downstreamConn
dc := &downstreamConn{
conn: *newConn(srv, netConn, logger),
id: id,
ringConsumers: make(map[*network]*RingConsumer),
ourMessages: make(map[*irc.Message]struct{}),
caps: make(map[string]bool),
}
@ -683,7 +681,6 @@ func (dc *downstreamConn) welcome() error {
}
consumer := net.ring.NewConsumer(seqPtr)
dc.ringConsumers[net] = consumer
// TODO: this means all history is lost when trying to send it while the
// upstream is disconnected. We need to store history differently so that

View File

@ -36,6 +36,10 @@ func (r *Ring) Produce(msg *irc.Message) {
r.cur++
}
func (r *Ring) Cur() uint64 {
return r.cur
}
func (r *Ring) Close() {
if r.closed {
panic("soju: Ring.Close called twice")

View File

@ -1367,7 +1367,7 @@ func (uc *upstreamConn) produce(msg *irc.Message) {
uc.network.ring.Produce(msg)
uc.forEachDownstream(func(dc *downstreamConn) {
dc.sendFromUpstream(dc.ringConsumers[uc.network].Consume(), uc)
dc.sendFromUpstream(msg, uc)
})
}

13
user.go
View File

@ -303,10 +303,10 @@ func (u *user) run() {
case eventDownstreamDisconnected:
dc := e.dc
for net, rc := range dc.ringConsumers {
seq := rc.Close()
dc.forEachNetwork(func(net *network) {
seq := net.ring.Cur()
net.history[dc.clientName] = seq
}
})
for i := range u.downstreamConns {
if u.downstreamConns[i] == dc {
@ -349,12 +349,6 @@ func (u *user) createNetwork(net *Network) (*network, error) {
return nil, err
}
u.forEachDownstream(func(dc *downstreamConn) {
if dc.network == nil {
dc.ringConsumers[network] = network.ring.NewConsumer(nil)
}
})
u.networks = append(u.networks, network)
go network.run()
@ -375,7 +369,6 @@ func (u *user) deleteNetwork(id int64) error {
if dc.network != nil && dc.network == net {
dc.Close()
}
delete(dc.ringConsumers, net)
})
net.Stop()