Changeset 261 in code for trunk/downstream.go


Ignore:
Timestamp:
Apr 16, 2020, 3:23:35 PM (5 years ago)
Author:
contact
Message:

Support sending history when upstream is disconnected

Previously, we were dropping the history.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r260 r261  
    239239// that it's suitable for being sent on this downstream connection. Only
    240240// messages that may appear in logs are supported.
    241 func (dc *downstreamConn) marshalMessage(msg *irc.Message, uc *upstreamConn) *irc.Message {
     241func (dc *downstreamConn) marshalMessage(msg *irc.Message, net *network) *irc.Message {
    242242        msg = msg.Copy()
    243         msg.Prefix = dc.marshalUserPrefix(uc.network, msg.Prefix)
     243        msg.Prefix = dc.marshalUserPrefix(net, msg.Prefix)
    244244
    245245        switch msg.Command {
    246246        case "PRIVMSG", "NOTICE":
    247                 msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0])
     247                msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
    248248        case "NICK":
    249249                // Nick change for another user
    250                 msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0])
     250                msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
    251251        case "JOIN", "PART":
    252                 msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0])
     252                msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
    253253        case "KICK":
    254                 msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0])
    255                 msg.Params[1] = dc.marshalEntity(uc.network, msg.Params[1])
     254                msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
     255                msg.Params[1] = dc.marshalEntity(net, msg.Params[1])
    256256        case "TOPIC":
    257                 msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0])
     257                msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
    258258        case "MODE":
    259                 msg.Params[0] = dc.marshalEntity(uc.network, msg.Params[0])
     259                msg.Params[0] = dc.marshalEntity(net, msg.Params[0])
    260260        case "QUIT":
    261261                // This space is intentinally left blank
     
    711711                consumer := history.ring.NewConsumer(seq)
    712712
    713                 // TODO: this means all history is lost when trying to send it while the
    714                 // upstream is disconnected. We need to store history differently so that
    715                 // we don't need access to upstreamConn to forward it to a downstream
    716                 // client.
    717                 uc := net.upstream()
    718                 if uc == nil {
    719                         dc.logger.Printf("ignoring messages for upstream %q: upstream is disconnected", net.Addr)
    720                         return
    721                 }
    722 
    723713                batchRef := "history"
    724714                if dc.caps["batch"] {
     
    753743                        }
    754744
    755                         dc.SendMessage(dc.marshalMessage(msg, uc))
     745                        dc.SendMessage(dc.marshalMessage(msg, net))
    756746                }
    757747
Note: See TracChangeset for help on using the changeset viewer.