aboutsummaryrefslogtreecommitdiff
path: root/prototypes
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2018-07-22 14:55:15 +0200
committerPřemysl Janouch <p@janouch.name>2018-07-22 14:55:15 +0200
commita8f02e0d3734bf3f2ba2f157630e05923175173b (patch)
tree664bf8c7fa23907e78681ca9a6705502c8f5ed62 /prototypes
parent525734eeb346f4051eeac16be7ee34d181caab2d (diff)
downloadhaven-a8f02e0d3734bf3f2ba2f157630e05923175173b.tar.gz
haven-a8f02e0d3734bf3f2ba2f157630e05923175173b.tar.xz
haven-a8f02e0d3734bf3f2ba2f157630e05923175173b.zip
tls-autodetect: finish inQ overrun handling
Diffstat (limited to 'prototypes')
-rw-r--r--prototypes/tls-autodetect.go27
1 files changed, 17 insertions, 10 deletions
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)