Rename consumption to ringMessage

This commit is contained in:
Simon Ser 2020-03-16 14:05:48 +01:00
parent 3919ee2036
commit d5db7c988f
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -47,7 +47,7 @@ var errAuthFailed = ircError{&irc.Message{
Params: []string{"*", "Invalid username or password"}, Params: []string{"*", "Invalid username or password"},
}} }}
type consumption struct { type ringMessage struct {
consumer *RingConsumer consumer *RingConsumer
upstreamConn *upstreamConn upstreamConn *upstreamConn
} }
@ -58,7 +58,7 @@ type downstreamConn struct {
srv *Server srv *Server
logger Logger logger Logger
outgoing chan *irc.Message outgoing chan *irc.Message
consumptions chan consumption ringMessages chan ringMessage
closed chan struct{} closed chan struct{}
registered bool registered bool
@ -78,7 +78,7 @@ func newDownstreamConn(srv *Server, netConn net.Conn) *downstreamConn {
srv: srv, srv: srv,
logger: &prefixLogger{srv.Logger, fmt.Sprintf("downstream %q: ", netConn.RemoteAddr())}, logger: &prefixLogger{srv.Logger, fmt.Sprintf("downstream %q: ", netConn.RemoteAddr())},
outgoing: make(chan *irc.Message, 64), outgoing: make(chan *irc.Message, 64),
consumptions: make(chan consumption), ringMessages: make(chan ringMessage),
closed: make(chan struct{}), closed: make(chan struct{}),
} }
@ -222,8 +222,8 @@ func (dc *downstreamConn) writeMessages() error {
dc.logger.Printf("sent: %v", msg) dc.logger.Printf("sent: %v", msg)
} }
err = dc.irc.WriteMessage(msg) err = dc.irc.WriteMessage(msg)
case consumption := <-dc.consumptions: case ringMessage := <-dc.ringMessages:
consumer, uc := consumption.consumer, consumption.upstreamConn consumer, uc := ringMessage.consumer, ringMessage.upstreamConn
for { for {
msg := consumer.Peek() msg := consumer.Peek()
if msg == nil { if msg == nil {
@ -427,7 +427,6 @@ func (dc *downstreamConn) register() error {
}) })
dc.forEachUpstream(func(uc *upstreamConn) { dc.forEachUpstream(func(uc *upstreamConn) {
// TODO: fix races accessing upstream connection data
for _, ch := range uc.channels { for _, ch := range uc.channels {
if ch.complete { if ch.complete {
forwardChannel(dc, ch) forwardChannel(dc, ch)
@ -450,7 +449,7 @@ func (dc *downstreamConn) register() error {
var closed bool var closed bool
select { select {
case <-ch: case <-ch:
dc.consumptions <- consumption{consumer, uc} dc.ringMessages <- ringMessage{consumer, uc}
case <-dc.closed: case <-dc.closed:
closed = true closed = true
} }