Remove downstreamConn.ourMessages

We can just do the filtering when dispatching the message.
This commit is contained in:
Simon Ser 2020-04-06 19:08:43 +02:00
parent 78b123be72
commit 1c17d25731
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48

View file

@ -66,11 +66,9 @@ type downstreamConn struct {
password string // empty after authentication password string // empty after authentication
network *network // can be nil network *network // can be nil
ourMessages map[*irc.Message]struct{}
caps map[string]bool
negociatingCaps bool negociatingCaps bool
capVersion int capVersion int
caps map[string]bool
saslServer sasl.Server saslServer sasl.Server
} }
@ -78,10 +76,9 @@ type downstreamConn struct {
func newDownstreamConn(srv *Server, netConn net.Conn, id uint64) *downstreamConn { func newDownstreamConn(srv *Server, netConn net.Conn, id uint64) *downstreamConn {
logger := &prefixLogger{srv.Logger, fmt.Sprintf("downstream %q: ", netConn.RemoteAddr())} logger := &prefixLogger{srv.Logger, fmt.Sprintf("downstream %q: ", netConn.RemoteAddr())}
dc := &downstreamConn{ dc := &downstreamConn{
conn: *newConn(srv, netConn, logger), conn: *newConn(srv, netConn, logger),
id: id, id: id,
ourMessages: make(map[*irc.Message]struct{}), caps: make(map[string]bool),
caps: make(map[string]bool),
} }
dc.hostname = netConn.RemoteAddr().String() dc.hostname = netConn.RemoteAddr().String()
if host, _, err := net.SplitHostPort(dc.hostname); err == nil { if host, _, err := net.SplitHostPort(dc.hostname); err == nil {
@ -226,14 +223,6 @@ func (dc *downstreamConn) SendMessage(msg *irc.Message) {
} }
func (dc *downstreamConn) sendFromUpstream(msg *irc.Message, uc *upstreamConn) { func (dc *downstreamConn) sendFromUpstream(msg *irc.Message, uc *upstreamConn) {
_, ours := dc.ourMessages[msg]
delete(dc.ourMessages, msg)
if ours && !dc.caps["echo-message"] {
// The message comes from our connection, don't echo it
// back
return
}
msg = msg.Copy() msg = msg.Copy()
switch msg.Command { switch msg.Command {
case "PRIVMSG", "NOTICE": case "PRIVMSG", "NOTICE":
@ -1196,11 +1185,16 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
Command: "PRIVMSG", Command: "PRIVMSG",
Params: []string{upstreamName, text}, Params: []string{upstreamName, text},
} }
dc.ourMessages[echoMsg] = struct{}{}
uc.appendLog(upstreamName, echoMsg) uc.appendLog(upstreamName, echoMsg)
uc.produce(echoMsg) uc.network.ring.Produce(echoMsg)
uc.forEachDownstream(func(c *downstreamConn) {
if c != dc || c.caps["echo-message"] {
c.sendFromUpstream(echoMsg, uc)
}
})
} }
case "NOTICE": case "NOTICE":
var targetsStr, text string var targetsStr, text string