A net.Conn implementation which can change tls.TLSConn from net.TCPConn when a TLS ClientHello received. It should be used with net.TCPListener.Accept() as underlying connection for BufferConn and the BufferConn should be used for Conn as underlying connection. For implementation example check the test files.
type BufferConn struct {
}
BufferConn implements the net.Conn interface. It has an internal buffer and when there is data in it the Read returns the data from the buffer and delete the buffer instead of reading the underlying connection.
func CreateBufferConn(connection net.Conn) *BufferConn
CreateBufferConn returns a new BufferConn using connection as the underlying connection.
func (connection *BufferConn) Close() error
Close the underlying connection.
func (connection *BufferConn) GetBuffer() []byte
GetBuffer read the data from the buffer and delete the data from it.
func (connection *BufferConn) LocalAddr() net.Addr
LocalAddr of the underlying connection.
func (connection *BufferConn) Read(buffer []byte) (int, error)
Read returns the data from the buffer and delete the buffer instead of reading the underlying connection if the internal buffer has data.
func (connection *BufferConn) RemoteAddr() net.Addr
RemoteAddr of the underlying connection.
func (connection *BufferConn) SetBuffer(buffer []byte)
SetBuffer the internal buffer will be equal to buffer. If there was data in the internal buffer it will be overwritten.
func (connection *BufferConn) SetDeadline(time time.Time) error
SetDeadline to the underlying connection.
func (connection *BufferConn) SetReadDeadline(time time.Time) error
SetReadDeadline to the underlying connection.
func (connection *BufferConn) SetWriteDeadline(time time.Time) error
SetWriteDeadline to the underlying connection.
func (connection *BufferConn) Write(buffer []byte) (int, error)
Write to the underlying connection.
type Conn struct {
}
Conn implements the net.Conn interface. Which can change the underlying connection from TCP to TLS if a TLS ClientHello received.
func New(connection net.Conn, tlsConfig *tls.Config) *Conn
New returns a new Conn using connection converted to BufferConn as the underlying connection. The configuration config must be non-nil and must include at least one certificate or else set GetCertificate, if TLS will be added to the connection.
func (connection *Conn) Close() error
Close the underlying connection.
func (connection *Conn) GetTls() bool
GetTls returns true if the underlying connection is using TLS and false if not.
func (connection *Conn) GetTlsConfig() *tls.Config
GetTlsConfig returns the TLS server configuration.
func (connection *Conn) LocalAddr() net.Addr
LocalAddr of the underlying connection.
func (connection *Conn) Read(buffer []byte) (int, error)
Read from the underlying connection. If TLS ClientHello received execute tls.TLSConn.Handshake() and read again for the actual message.
func (connection *Conn) RemoteAddr() net.Addr
RemoteAddr of the underlying connection.
func (connection *Conn) SetDeadline(time time.Time) error
SetDeadline to the underlying connection.
func (connection *Conn) SetReadDeadline(time time.Time) error
SetReadDeadline to the underlying connection.
func (connection *Conn) SetTlsConfig(tlsConfig *tls.Config)
SetTlsConfig change the TLS server configuration. New connection will be not generated if you change it and TLS is already in use.
func (connection *Conn) SetWriteDeadline(time time.Time) error
SetWriteDeadline to the underlying connection.
func (connection *Conn) Write(buffer []byte) (int, error)
Write to the underlying connection.