From a8f02e0d3734bf3f2ba2f157630e05923175173b Mon Sep 17 00:00:00 2001 From: Přemysl Janouch
Date: Sun, 22 Jul 2018 14:55:15 +0200 Subject: tls-autodetect: finish inQ overrun handling --- prototypes/tls-autodetect.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'prototypes/tls-autodetect.go') diff --git a/prototypes/tls-autodetect.go b/prototypes/tls-autodetect.go index aaff3d9..3ff4128 100644 --- a/prototypes/tls-autodetect.go +++ b/prototypes/tls-autodetect.go @@ -218,12 +218,18 @@ func (c *client) onPrepared(host string, isTLS bool) { } // TODO: Save the host in the client structure. + // TODO: If we've tried to send any data before now, we need to flushOutQ. go read(c) c.reading = true } // Handle the results from trying to read from the client connection. func (c *client) onRead(data []byte, readErr error) { + if !c.reading { + // Abusing the flag to emulate CloseRead and skip over data, see below. + return + } + c.inQ = append(c.inQ, data...) for { advance, token, _ := bufio.ScanLines(c.inQ, false /* atEOF */) @@ -237,14 +243,6 @@ func (c *client) onRead(data []byte, readErr error) { broadcast(line, c) } - // TODO: Inform the client about the inQ overrun in the farewell message. - // TODO: We should stop receiving any more data from this client, or at - // least stop extending the inQ if we don't want to signal tho goroutine. - if len(c.inQ) > 8192 { - c.closeLink() - return - } - if readErr != nil { c.reading = false @@ -259,11 +257,20 @@ func (c *client) onRead(data []byte, readErr error) { log.Println("client EOF") c.closeLink() } + } else if len(c.inQ) > 8192 { + log.Println("client inQ overrun") + // TODO: Inform the client about inQ overrun in the farewell message. + c.closeLink() + + // tls.Conn doesn't have the CloseRead method (and it needs to be able + // to read from the TCP connection even for writes, so there isn't much + // sense in expecting the implementation to do anything useful), + // otherwise we'd use it to block incoming packet data. + c.reading = false } } -// Spawn a goroutine to flush the outQ if possible and necessary. If the -// connection is not ready yet, it needs to be retried as soon as it becomes. +// Spawn a goroutine to flush the outQ if possible and necessary. func (c *client) flushOutQ() { if !c.writing && c.conn != nil { go write(c, c.outQ) -- cgit v1.2.3-70-g09d2