Changeset 302 in code for trunk/upstream.go


Ignore:
Timestamp:
May 27, 2020, 9:47:49 PM (5 years ago)
Author:
delthas
Message:

Forward all labeled errors and unknown messages to their downstream

This adds support for forwarding all errors and unknown messages labeled
with a specific downstream to that downstream.

Provided that the upstream supports labeled-response, users will now be
able to receive an error only on their client when making a command that
returns an error, as well as receiving any reply unknown to soju.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/upstream.go

    r300 r302  
    11831183                        })
    11841184                })
    1185         case irc.ERR_UNKNOWNCOMMAND, irc.RPL_TRYAGAIN:
    1186                 var command, reason string
    1187                 if err := parseMessageParams(msg, nil, &command, &reason); err != nil {
    1188                         return err
    1189                 }
    1190 
    1191                 if command == "LIST" {
    1192                         ok := uc.endPendingLISTs(false)
    1193                         if !ok {
    1194                                 return fmt.Errorf("unexpected response for LIST: %q: no matching pending LIST", msg.Command)
    1195                         }
    1196                         uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
    1197                                 dc.SendMessage(&irc.Message{
    1198                                         Prefix:  uc.srv.prefix(),
    1199                                         Command: msg.Command,
    1200                                         Params:  []string{dc.nick, "LIST", reason},
    1201                                 })
    1202                         })
    1203                 }
    12041185        case irc.RPL_AWAY:
    12051186                var nick, reason string
     
    12721253                        })
    12731254                })
     1255        case irc.ERR_UNKNOWNCOMMAND, irc.RPL_TRYAGAIN:
     1256                var command, reason string
     1257                if err := parseMessageParams(msg, nil, &command, &reason); err != nil {
     1258                        return err
     1259                }
     1260
     1261                if command == "LIST" {
     1262                        ok := uc.endPendingLISTs(false)
     1263                        if !ok {
     1264                                return fmt.Errorf("unexpected response for LIST: %q: no matching pending LIST", msg.Command)
     1265                        }
     1266                }
     1267
     1268                if downstreamID != 0 {
     1269                        uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
     1270                                dc.SendMessage(&irc.Message{
     1271                                        Prefix:  uc.srv.prefix(),
     1272                                        Command: msg.Command,
     1273                                        Params:  []string{dc.nick, command, reason},
     1274                                })
     1275                        })
     1276                }
    12741277        case "TAGMSG":
    12751278                // TODO: relay to downstream connections that accept message-tags
     
    12921295        default:
    12931296                uc.logger.Printf("unhandled message: %v", msg)
     1297                if downstreamID != 0 {
     1298                        uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
     1299                                // best effort marshaling for unknown messages, replies and errors:
     1300                                // most numerics start with the user nick, marshal it if that's the case
     1301                                // otherwise, conservately keep the params without marshaling
     1302                                params := msg.Params
     1303                                if _, err := strconv.Atoi(msg.Command); err == nil { // numeric
     1304                                        if len(msg.Params) > 0 && isOurNick(uc.network, msg.Params[0]) {
     1305                                                params[0] = dc.nick
     1306                                        }
     1307                                }
     1308                                dc.SendMessage(&irc.Message{
     1309                                        Prefix:  uc.srv.prefix(),
     1310                                        Command: msg.Command,
     1311                                        Params:  params,
     1312                                })
     1313                        })
     1314                }
    12941315        }
    12951316        return nil
Note: See TracChangeset for help on using the changeset viewer.