From b2cd8b46c9d84b4eacf6aa2c1ff871d99b2221a7 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch
Date: Tue, 24 Jul 2018 13:58:57 +0200 Subject: tls-autodetect: mark issues, fix initialization --- prototypes/tls-autodetect.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'prototypes') diff --git a/prototypes/tls-autodetect.go b/prototypes/tls-autodetect.go index 4ce665b..a5642d6 100644 --- a/prototypes/tls-autodetect.go +++ b/prototypes/tls-autodetect.go @@ -16,14 +16,14 @@ // // This is an example TLS-autodetecting chat server. // -// You may connect to it using either of these: -// ncat -C localhost 1234 -// ncat -C --ssl localhost 1234 -// -// These clients are unable to properly shutdown the connection: +// These clients are unable to properly shutdown the connection on their exit: // telnet localhost 1234 // openssl s_client -connect localhost:1234 // +// While this one doesn't react to an EOF from the server: +// ncat -C localhost 1234 +// ncat -C --ssl localhost 1234 +// package main import ( @@ -165,7 +165,7 @@ func forceShutdown(reason string) { // --- Client ------------------------------------------------------------------ func (c *client) send(line string) { - if !c.closing { + if c.conn != nil && !c.closing { c.outQ = append(c.outQ, (line + "\r\n")...) c.flushOutQ() } @@ -205,6 +205,7 @@ func (c *client) destroy() { c.killTimer.Stop() } + log.Println("client destroyed") delete(clients, c) } @@ -341,6 +342,8 @@ func prepare(client *client) { } } + // Note that in this demo application the autodetection prevents non-TLS + // clients from receiving any messages until they send something. isTLS := false if sysconn, err := conn.(syscall.Conn).SyscallConn(); err != nil { // This is just for the TLS detection and doesn't need to be fatal. @@ -349,6 +352,7 @@ func prepare(client *client) { isTLS = detectTLS(sysconn) } + // FIXME: When the client sends no data, we still initialize its conn. prepared <- preparedEvent{client, host, isTLS} } -- cgit v1.2.3-70-g09d2