Send a label with all messages sent from downstream

This is preparatory work for forwarding errors of downstream-initiated
messages to their sender, as well as any other unknown message.

Preivously, we only sent labels (for labeled-response) for specific
downstream messages, such as WHO, where we knew the reply should only be
sent to that specific downstream.

However, in the case of an error of a message that is not labeled, the
error reply is not be tagged with a downstream id label and we can't
forward it to a specific downstream. It is not a good solution either to
forward this error to all downstreams.

This adds labels to all downstream-initiated messages (provided the
upstream supports it).
This commit is contained in:
delthas 2020-05-19 17:27:43 +02:00 committed by Simon Ser
parent 96dad08302
commit f13a9c9d86
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -958,7 +958,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
if upstream != nil && upstream != uc { if upstream != nil && upstream != uc {
return return
} }
uc.SendMessage(&irc.Message{ uc.SendMessageLabeled(dc.id, &irc.Message{
Command: "NICK", Command: "NICK",
Params: []string{nick}, Params: []string{nick},
}) })
@ -998,7 +998,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
if key != "" { if key != "" {
params = append(params, key) params = append(params, key)
} }
uc.SendMessage(&irc.Message{ uc.SendMessageLabeled(dc.id, &irc.Message{
Command: "JOIN", Command: "JOIN",
Params: params, Params: params,
}) })
@ -1040,7 +1040,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
if reason != "" { if reason != "" {
params = append(params, reason) params = append(params, reason)
} }
uc.SendMessage(&irc.Message{ uc.SendMessageLabeled(dc.id, &irc.Message{
Command: "PART", Command: "PART",
Params: params, Params: params,
}) })
@ -1101,7 +1101,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
if reason != "" { if reason != "" {
params = append(params, reason) params = append(params, reason)
} }
uc.SendMessage(&irc.Message{ uc.SendMessageLabeled(dc.id, &irc.Message{
Command: "KICK", Command: "KICK",
Params: params, Params: params,
}) })
@ -1120,7 +1120,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
if name == dc.nick { if name == dc.nick {
if modeStr != "" { if modeStr != "" {
dc.forEachUpstream(func(uc *upstreamConn) { dc.forEachUpstream(func(uc *upstreamConn) {
uc.SendMessage(&irc.Message{ uc.SendMessageLabeled(dc.id, &irc.Message{
Command: "MODE", Command: "MODE",
Params: []string{uc.nick, modeStr}, Params: []string{uc.nick, modeStr},
}) })
@ -1150,7 +1150,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
if modeStr != "" { if modeStr != "" {
params := []string{upstreamName, modeStr} params := []string{upstreamName, modeStr}
params = append(params, msg.Params[2:]...) params = append(params, msg.Params[2:]...)
uc.SendMessage(&irc.Message{ uc.SendMessageLabeled(dc.id, &irc.Message{
Command: "MODE", Command: "MODE",
Params: params, Params: params,
}) })
@ -1199,7 +1199,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
if len(msg.Params) > 1 { // setting topic if len(msg.Params) > 1 { // setting topic
topic := msg.Params[1] topic := msg.Params[1]
uc.SendMessage(&irc.Message{ uc.SendMessageLabeled(dc.id, &irc.Message{
Command: "TOPIC", Command: "TOPIC",
Params: []string{upstreamChannel, topic}, Params: []string{upstreamChannel, topic},
}) })
@ -1417,7 +1417,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
if uc.isChannel(upstreamName) { if uc.isChannel(upstreamName) {
unmarshaledText = dc.unmarshalText(uc, text) unmarshaledText = dc.unmarshalText(uc, text)
} }
uc.SendMessage(&irc.Message{ uc.SendMessageLabeled(dc.id, &irc.Message{
Command: "PRIVMSG", Command: "PRIVMSG",
Params: []string{upstreamName, unmarshaledText}, Params: []string{upstreamName, unmarshaledText},
}) })
@ -1451,7 +1451,7 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
if uc.isChannel(upstreamName) { if uc.isChannel(upstreamName) {
unmarshaledText = dc.unmarshalText(uc, text) unmarshaledText = dc.unmarshalText(uc, text)
} }
uc.SendMessage(&irc.Message{ uc.SendMessageLabeled(dc.id, &irc.Message{
Command: "NOTICE", Command: "NOTICE",
Params: []string{upstreamName, unmarshaledText}, Params: []string{upstreamName, unmarshaledText},
}) })