aboutsummaryrefslogtreecommitdiff
path: root/prototypes/tls-autodetect.go
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2018-07-24 13:58:57 +0200
committerPřemysl Janouch <p@janouch.name>2018-07-24 13:58:57 +0200
commitb2cd8b46c9d84b4eacf6aa2c1ff871d99b2221a7 (patch)
treecda6f060ff29b826c0d4b31daf4ae32fca82e07c /prototypes/tls-autodetect.go
parente8602ee718866c83bf58e5cbe32ab1ab6b916969 (diff)
downloadhaven-b2cd8b46c9d84b4eacf6aa2c1ff871d99b2221a7.tar.gz
haven-b2cd8b46c9d84b4eacf6aa2c1ff871d99b2221a7.tar.xz
haven-b2cd8b46c9d84b4eacf6aa2c1ff871d99b2221a7.zip
tls-autodetect: mark issues, fix initialization
Diffstat (limited to 'prototypes/tls-autodetect.go')
-rw-r--r--prototypes/tls-autodetect.go16
1 files changed, 10 insertions, 6 deletions
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}
}