Skip to content
Snippets Groups Projects
Commit 4d4fad30 authored by David Fifield's avatar David Fifield
Browse files

Have SnowflakeClientConn implement io.WriterTo.

By forwarding the method to the inner smux.Stream. This is to prevent
io.Copy in the top-level proxy function from allocating a buffer per
client.
parent 855ca0b8
No related branches found
No related tags found
No related merge requests found
......@@ -235,7 +235,7 @@ func (l *SnowflakeListener) acceptStreams(conn *kcp.UDPSession) error {
}
return err
}
l.queueConn(&SnowflakeClientConn{Conn: stream, address: addr})
l.queueConn(&SnowflakeClientConn{stream: stream, address: addr})
}
}
......@@ -283,15 +283,31 @@ func (l *SnowflakeListener) queueConn(conn net.Conn) error {
}
}
// SnowflakeClientConn is a wrapper for the underlying turbotunnel
// conn. We need to reference our client address map to determine the
// remote address
// SnowflakeClientConn is a wrapper for the underlying turbotunnel conn
// (smux.String). It implements the net.Conn and io.WriterTo interfaces. The
// RemoteAddr method is overridden to refer to a real IP address, looked up from
// the client address map, rather than an abstract client ID.
type SnowflakeClientConn struct {
net.Conn
stream *smux.Stream
address net.Addr
}
// RemoteAddr returns the mapped client address of the Snowflake connection
// Forward net.Conn methods, other than RemoteAddr, to the inner stream.
func (conn *SnowflakeClientConn) Read(b []byte) (int, error) { return conn.stream.Read(b) }
func (conn *SnowflakeClientConn) Write(b []byte) (int, error) { return conn.stream.Write(b) }
func (conn *SnowflakeClientConn) Close() error { return conn.stream.Close() }
func (conn *SnowflakeClientConn) LocalAddr() net.Addr { return conn.stream.LocalAddr() }
func (conn *SnowflakeClientConn) SetDeadline(t time.Time) error { return conn.stream.SetDeadline(t) }
func (conn *SnowflakeClientConn) SetReadDeadline(t time.Time) error { return conn.stream.SetReadDeadline(t) }
func (conn *SnowflakeClientConn) SetWriteDeadline(t time.Time) error { return conn.stream.SetWriteDeadline(t) }
// RemoteAddr returns the mapped client address of the Snowflake connection.
func (conn *SnowflakeClientConn) RemoteAddr() net.Addr {
return conn.address
}
// WriteTo implements the io.WriterTo interface by passing the call to the
// underlying smux.Stream.
func (conn *SnowflakeClientConn) WriteTo(w io.Writer) (int64, error) {
return conn.stream.WriteTo(w)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment