|
@ -10,7 +10,6 @@ import ( |
|
|
"encoding/base64" |
|
|
"encoding/base64" |
|
|
"flag" |
|
|
"flag" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"io" |
|
|
|
|
|
"io/ioutil" |
|
|
"io/ioutil" |
|
|
"net" |
|
|
"net" |
|
|
"net/http" |
|
|
"net/http" |
|
@ -43,12 +42,12 @@ type ConfMailer struct { |
|
|
// https://stackoverflow.com/questions/51472020/how-to-get-the-size-of-available-tcp-data
|
|
|
// https://stackoverflow.com/questions/51472020/how-to-get-the-size-of-available-tcp-data
|
|
|
type bufferedConn struct { |
|
|
type bufferedConn struct { |
|
|
r *bufio.Reader |
|
|
r *bufio.Reader |
|
|
rout io.Reader // See https://github.com/polvi/sni/blob/master/sni.go#L135
|
|
|
//rout *io.Reader // See https://github.com/polvi/sni/blob/master/sni.go#L135
|
|
|
net.Conn |
|
|
net.Conn |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func newBufferedConn(c net.Conn) bufferedConn { |
|
|
func newBufferedConn(c net.Conn) bufferedConn { |
|
|
return bufferedConn{bufio.NewReader(c), nil, c} |
|
|
return bufferedConn{bufio.NewReader(c), c} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (b bufferedConn) Peek(n int) ([]byte, error) { |
|
|
func (b bufferedConn) Peek(n int) ([]byte, error) { |
|
@ -60,9 +59,11 @@ func (b bufferedConn) Buffered() int { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (b bufferedConn) Read(p []byte) (int, error) { |
|
|
func (b bufferedConn) Read(p []byte) (int, error) { |
|
|
|
|
|
/* |
|
|
if b.rout != nil { |
|
|
if b.rout != nil { |
|
|
return b.rout.Read(p) |
|
|
return b.rout.Read(p) |
|
|
} |
|
|
} |
|
|
|
|
|
*/ |
|
|
return b.r.Read(p) |
|
|
return b.r.Read(p) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -166,6 +167,9 @@ func muxTcp(conn bufferedConn) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if "" == protocol { |
|
|
if "" == protocol { |
|
|
|
|
|
// Throw away the first bytes
|
|
|
|
|
|
b := make([]byte, 4096) |
|
|
|
|
|
conn.Read(b) |
|
|
fmt.Fprintf(conn, "\n\nWelcome to Sample Chat! You're not an HTTP client, assuming Telnet.\nYou must authenticate via email to participate\n\nEmail: ") |
|
|
fmt.Fprintf(conn, "\n\nWelcome to Sample Chat! You're not an HTTP client, assuming Telnet.\nYou must authenticate via email to participate\n\nEmail: ") |
|
|
wantsServerHello <- conn |
|
|
wantsServerHello <- conn |
|
|
return |
|
|
return |
|
|