3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

Merge pull request #1660 from ergochat/relay_nuh.1

fix #1647
This commit is contained in:
Shivaram Lingamneni 2021-05-27 02:24:08 -04:00 committed by GitHub
commit 98ea150817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 12 deletions

View File

@ -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")
}
}

View File

@ -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)
}
}
}