Add support for downstream echo-message extension

This commit is contained in:
Simon Ser 2020-04-03 16:55:49 +02:00
parent 2a0696b6bb
commit 0dc007cd45
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -379,7 +379,7 @@ func (dc *downstreamConn) handleCapCommand(cmd string, args []string) error {
} }
} }
caps := []string{"message-tags", "server-time"} caps := []string{"message-tags", "server-time", "echo-message"}
if dc.capVersion >= 302 { if dc.capVersion >= 302 {
caps = append(caps, "sasl=PLAIN") caps = append(caps, "sasl=PLAIN")
@ -432,7 +432,7 @@ func (dc *downstreamConn) handleCapCommand(cmd string, args []string) error {
} }
switch name { switch name {
case "sasl", "message-tags", "server-time": case "sasl", "message-tags", "server-time", "echo-message":
dc.caps[name] = enable dc.caps[name] = enable
default: default:
ack = false ack = false
@ -666,6 +666,7 @@ func (dc *downstreamConn) runNetwork(net *network, loadHistory bool) {
// TODO: can't be enabled/disabled on-the-fly // TODO: can't be enabled/disabled on-the-fly
msgTagsEnabled := dc.caps["message-tags"] msgTagsEnabled := dc.caps["message-tags"]
serverTimeEnabled := dc.caps["server-time"] serverTimeEnabled := dc.caps["server-time"]
echoMessageEnabled := dc.caps["echo-message"]
consumer, ch := net.ring.NewConsumer(seqPtr) consumer, ch := net.ring.NewConsumer(seqPtr)
@ -692,7 +693,7 @@ func (dc *downstreamConn) runNetwork(net *network, loadHistory bool) {
_, ours := dc.ourMessages[msg] _, ours := dc.ourMessages[msg]
delete(dc.ourMessages, msg) delete(dc.ourMessages, msg)
dc.lock.Unlock() dc.lock.Unlock()
if ours { if ours && !echoMessageEnabled {
// The message comes from our connection, don't echo it // The message comes from our connection, don't echo it
// back // back
consumer.Consume() consumer.Consume()