Support sending history when upstream is disconnected

Previously, we were dropping the history.
This commit is contained in:
Simon Ser 2020-04-16 17:23:35 +02:00
parent 45e897c1c1
commit 3e80573765
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 13 additions and 23 deletions

View File

@ -238,25 +238,25 @@ func (dc *downstreamConn) SendMessage(msg *irc.Message) {
// marshalMessage re-formats a message coming from an upstream connection so
// that it's suitable for being sent on this downstream connection. Only
// messages that may appear in logs are supported.
func (dc *downstreamConn) marshalMessage(msg *irc.Message, uc *upstreamConn) *irc.Message {
func (dc *downstreamConn) marshalMessage(msg *irc.Message, net *network) *irc.Message {
msg = msg.Copy()
msg.Prefix = dc.marshalUserPrefix(uc.network, msg.Prefix)
msg.Prefix = dc.marshalUserPrefix(net, msg.Prefix)
switch msg.Command {
case "PRIVMSG", "NOTICE":
msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0])
msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
case "NICK":
// Nick change for another user
msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0])
msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
case "JOIN", "PART":
msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0])
msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
case "KICK":
msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0])
msg.Params[1] = dc.marshalEntity(uc.network, msg.Params[1])
msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
msg.Params[1] = dc.marshalEntity(net, msg.Params[1])
case "TOPIC":
msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0])
msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
case "MODE":
msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0])
msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
case "QUIT":
// This space is intentinally left blank
default:
@ -710,16 +710,6 @@ func (dc *downstreamConn) sendNetworkHistory(net *network) {
consumer := history.ring.NewConsumer(seq)
// 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
// we don't need access to upstreamConn to forward it to a downstream
// client.
uc := net.upstream()
if uc == nil {
dc.logger.Printf("ignoring messages for upstream %q: upstream is disconnected", net.Addr)
return
}
batchRef := "history"
if dc.caps["batch"] {
dc.SendMessage(&irc.Message{
@ -752,7 +742,7 @@ func (dc *downstreamConn) sendNetworkHistory(net *network) {
msg.Tags["batch"] = irc.TagValue(batchRef)
}
dc.SendMessage(dc.marshalMessage(msg, uc))
dc.SendMessage(dc.marshalMessage(msg, net))
}
if dc.caps["batch"] {

View File

@ -562,7 +562,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
if !me {
uc.forEachDownstream(func(dc *downstreamConn) {
dc.SendMessage(dc.marshalMessage(msg, uc))
dc.SendMessage(dc.marshalMessage(msg, uc.network))
})
}
case "JOIN":
@ -668,7 +668,7 @@ func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
if msg.Prefix.Name != uc.nick {
uc.forEachDownstream(func(dc *downstreamConn) {
dc.SendMessage(dc.marshalMessage(msg, uc))
dc.SendMessage(dc.marshalMessage(msg, uc.network))
})
}
case irc.RPL_TOPIC, irc.RPL_NOTOPIC:
@ -1331,7 +1331,7 @@ func (uc *upstreamConn) produce(target string, msg *irc.Message, origin *downstr
uc.forEachDownstream(func(dc *downstreamConn) {
if dc != origin || dc.caps["echo-message"] {
dc.SendMessage(dc.marshalMessage(msg, uc))
dc.SendMessage(dc.marshalMessage(msg, uc.network))
}
})
}