From a64e1d676156f7f95852da4337f55f3794ffc1f4 Mon Sep 17 00:00:00 2001 From: delthas Date: Fri, 8 May 2020 20:27:21 +0200 Subject: [PATCH] Add support for downstream LIST to a single upstream Sometimes, doing a LIST on a single upstream can be useful: if a user is already connected to Rizon and freenode, sending a LIST will contain tens of thousands of LIST replies that may not be useful if the user is interested in another upstream. This adds support for sending `LIST */network`, which follows the ELIST M mask extension, that will only send LIST to that specific network. No other masks are supported by this commit. --- downstream.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/downstream.go b/downstream.go index 09ffb67..3c80800 100644 --- a/downstream.go +++ b/downstream.go @@ -1220,21 +1220,30 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error { downstreamID: dc.id, pendingCommands: make(map[int64]*irc.Message), } + var upstream *upstreamConn var upstreamChannels map[int64][]string if len(msg.Params) > 0 { - upstreamChannels = make(map[int64][]string) - channels := strings.Split(msg.Params[0], ",") - for _, channel := range channels { - uc, upstreamChannel, err := dc.unmarshalEntity(channel) - if err != nil { - return err + uc, upstreamMask, err := dc.unmarshalEntity(msg.Params[0]) + if err == nil && upstreamMask == "*" { // LIST */network: send LIST only to one network + upstream = uc + } else { + upstreamChannels = make(map[int64][]string) + channels := strings.Split(msg.Params[0], ",") + for _, channel := range channels { + uc, upstreamChannel, err := dc.unmarshalEntity(channel) + if err != nil { + return err + } + upstreamChannels[uc.network.ID] = append(upstreamChannels[uc.network.ID], upstreamChannel) } - upstreamChannels[uc.network.ID] = append(upstreamChannels[uc.network.ID], upstreamChannel) } } dc.user.pendingLISTs = append(dc.user.pendingLISTs, pl) dc.forEachUpstream(func(uc *upstreamConn) { + if upstream != nil && upstream != uc { + return + } var params []string if upstreamChannels != nil { if channels, ok := upstreamChannels[uc.network.ID]; ok {