Changeset 428 in code for trunk/upstream.go


Ignore:
Timestamp:
Nov 24, 2020, 1:13:24 PM (5 years ago)
Author:
contact
Message:

Implement delivery receipts via PING messages

This patch implements basic message delivery receipts via PING and PONG.

When a PRIVMSG or NOTICE message is sent, a PING message with a token is
also sent. The history cursor isn't immediately advanced, instead the
bouncer will wait for a PONG message before doing so.

Self-messages trigger a PING for simplicity's sake. We can't immediately
advance the history cursor in this case, because a prior message might
still have an outstanding PING.

Future work may include optimizations such as removing the need to send
a PING after a self-message, or groupping multiple PING messages
together.

Closes: https://todo.sr.ht/~emersion/soju/11

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/upstream.go

    r423 r428  
    16081608}
    16091609
    1610 func (uc *upstreamConn) appendLog(entity string, msg *irc.Message) {
     1610// appendLog appends a message to the log file.
     1611//
     1612// The internal message ID is returned. If the message isn't recorded in the
     1613// log file, an empty string is returned.
     1614func (uc *upstreamConn) appendLog(entity string, msg *irc.Message) (msgID string) {
    16111615        if uc.user.msgStore == nil {
    1612                 return
     1616                return ""
    16131617        }
    16141618
     
    16231627                if err != nil {
    16241628                        uc.logger.Printf("failed to log message: failed to get last message ID: %v", err)
    1625                         return
     1629                        return ""
    16261630                }
    16271631
     
    16471651        if err != nil {
    16481652                uc.logger.Printf("failed to log message: %v", err)
    1649                 return
    1650         }
    1651 
    1652         if !detached && msgID != "" {
    1653                 uc.forEachDownstream(func(dc *downstreamConn) {
    1654                         history.clients[dc.clientName] = msgID
    1655                 })
    1656         }
     1653                return ""
     1654        }
     1655
     1656        return msgID
    16571657}
    16581658
     
    16631663// forwarded to all connections except origin.
    16641664func (uc *upstreamConn) produce(target string, msg *irc.Message, origin *downstreamConn) {
     1665        var msgID string
    16651666        if target != "" {
    1666                 uc.appendLog(target, msg)
     1667                msgID = uc.appendLog(target, msg)
    16671668        }
    16681669
     
    16741675        uc.forEachDownstream(func(dc *downstreamConn) {
    16751676                if dc != origin || dc.caps["echo-message"] {
    1676                         dc.SendMessage(dc.marshalMessage(msg, uc.network))
     1677                        dc.sendMessageWithID(dc.marshalMessage(msg, uc.network), msgID)
     1678                } else {
     1679                        dc.advanceMessageWithID(msg, msgID)
    16771680                }
    16781681        })
Note: See TracChangeset for help on using the changeset viewer.