From 77313e20ad5ce5961f088f703f0100f799de3b63 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Thu, 27 May 2021 02:00:59 -0400 Subject: [PATCH] fix #1647 Send a full NUH with RELAYMSG. Also fix client-only tags with RELAYMSG. --- irc/cloaks/cloak_test.go | 8 +++++++ irc/handlers.go | 47 ++++++++++++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/irc/cloaks/cloak_test.go b/irc/cloaks/cloak_test.go index 2b67249c..d4464b9a 100644 --- a/irc/cloaks/cloak_test.go +++ b/irc/cloaks/cloak_test.go @@ -126,3 +126,11 @@ func TestAccountCloakCollisions(t *testing.T) { t.Errorf("cloak collision between 97.97.97.97 and aaaa: %s", v4cloak) } } + +func BenchmarkAccountCloaks(b *testing.B) { + config := cloakConfForTesting() + b.ResetTimer() + for i := 0; i < b.N; i++ { + config.ComputeAccountCloak("shivaram") + } +} diff --git a/irc/handlers.go b/irc/handlers.go index ed8cb422..a418f4ce 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -2658,31 +2658,54 @@ func relaymsgHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res return false } + // #1647: we need to publish a full NUH. send ~u (or the configured alternative) + // as the user/ident, and send the relayer's hostname as the hostname: + ident := config.Server.CoerceIdent + if ident == "" { + ident = "~u" + } + hostname := client.Hostname() + nuh := fmt.Sprintf("%s!%s@%s", nick, ident, hostname) + channel.AddHistoryItem(history.Item{ Type: history.Privmsg, Message: message, - Nick: nick, + Nick: nuh, }, "") - // send msg + // 3 possibilities for tags: + // no tags, the relaymsg tag only, or the relaymsg tag together with all client-only tags + cnick := client.Nick() + relayTag := map[string]string{ + caps.RelaymsgTagName: cnick, + } + clientOnlyTags := msg.ClientOnlyTags() + var fullTags map[string]string + if len(clientOnlyTags) == 0 { + fullTags = relayTag + } else { + fullTags = make(map[string]string, 1+len(clientOnlyTags)) + fullTags[caps.RelaymsgTagName] = cnick + for t, v := range clientOnlyTags { + fullTags[t] = v + } + } + + // actually send the message channelName := channel.Name() - relayTags := map[string]string{ - caps.RelaymsgTagName: client.Nick(), - } - for t, v := range msg.ClientOnlyTags() { - relayTags[t] = v - } for _, member := range channel.Members() { for _, session := range member.Sessions() { var tagsToUse map[string]string - if session.capabilities.Has(caps.Relaymsg) { - tagsToUse = relayTags + if session.capabilities.Has(caps.MessageTags) { + tagsToUse = fullTags + } else if session.capabilities.Has(caps.Relaymsg) { + tagsToUse = relayTag } if session == rb.session { - rb.AddSplitMessageFromClient(nick, "*", false, tagsToUse, "PRIVMSG", channelName, message) + rb.AddSplitMessageFromClient(nuh, "*", false, tagsToUse, "PRIVMSG", channelName, message) } else { - session.sendSplitMsgFromClientInternal(false, nick, "*", false, tagsToUse, "PRIVMSG", channelName, message) + session.sendSplitMsgFromClientInternal(false, nuh, "*", false, tagsToUse, "PRIVMSG", channelName, message) } } }