Skip to content
Snippets Groups Projects
Commit 4623c7d3 authored by Cecylia Bocovich's avatar Cecylia Bocovich
Browse files

Add documentation where necessary for exported items

parent 5339ed2d
No related branches found
No related tags found
No related merge requests found
...@@ -193,6 +193,7 @@ func turbotunnelMode(conn net.Conn, addr net.Addr, pconn *turbotunnel.QueuePacke ...@@ -193,6 +193,7 @@ func turbotunnelMode(conn net.Conn, addr net.Addr, pconn *turbotunnel.QueuePacke
return nil return nil
} }
// ClientMapAddr is a string that represents a connecting client.
type ClientMapAddr string type ClientMapAddr string
func (addr ClientMapAddr) Network() string { func (addr ClientMapAddr) Network() string {
......
...@@ -17,7 +17,9 @@ import ( ...@@ -17,7 +17,9 @@ import (
) )
const ( const (
// WindowSize is the number of packets in the send and receive window of a KCP connection.
WindowSize = 65535 WindowSize = 65535
// StreamSize controls the maximum amount of in flight data between a client and server.
StreamSize = 1048576 //1MB StreamSize = 1048576 //1MB
) )
...@@ -27,11 +29,14 @@ type Transport struct { ...@@ -27,11 +29,14 @@ type Transport struct {
getCertificate func(*tls.ClientHelloInfo) (*tls.Certificate, error) getCertificate func(*tls.ClientHelloInfo) (*tls.Certificate, error)
} }
// NewSnowflakeServer returns a new server-side Transport for Snowflake.
func NewSnowflakeServer(getCertificate func(*tls.ClientHelloInfo) (*tls.Certificate, error)) *Transport { func NewSnowflakeServer(getCertificate func(*tls.ClientHelloInfo) (*tls.Certificate, error)) *Transport {
return &Transport{getCertificate: getCertificate} return &Transport{getCertificate: getCertificate}
} }
// Listen starts a listener on addr that will accept both turbotunnel
// and legacy Snowflake connections.
func (t *Transport) Listen(addr net.Addr) (*SnowflakeListener, error) { func (t *Transport) Listen(addr net.Addr) (*SnowflakeListener, error) {
listener := &SnowflakeListener{addr: addr, queue: make(chan net.Conn, 65534)} listener := &SnowflakeListener{addr: addr, queue: make(chan net.Conn, 65534)}
...@@ -129,9 +134,9 @@ type SnowflakeListener struct { ...@@ -129,9 +134,9 @@ type SnowflakeListener struct {
closeOnce sync.Once closeOnce sync.Once
} }
// Allows the caller to accept incoming Snowflake connections // Accept allows the caller to accept incoming Snowflake connections.
// We accept connections from a queue to accommodate both incoming // We accept connections from a queue to accommodate both incoming
// smux Streams and legacy non-turbotunnel connections // smux Streams and legacy non-turbotunnel connections.
func (l *SnowflakeListener) Accept() (net.Conn, error) { func (l *SnowflakeListener) Accept() (net.Conn, error) {
select { select {
case <-l.closed: case <-l.closed:
...@@ -142,10 +147,12 @@ func (l *SnowflakeListener) Accept() (net.Conn, error) { ...@@ -142,10 +147,12 @@ func (l *SnowflakeListener) Accept() (net.Conn, error) {
} }
} }
// Addr returns the address of the SnowflakeListener
func (l *SnowflakeListener) Addr() net.Addr { func (l *SnowflakeListener) Addr() net.Addr {
return l.addr return l.addr
} }
// Close closes the Snowflake connection.
func (l *SnowflakeListener) Close() error { func (l *SnowflakeListener) Close() error {
// Close our HTTP server and our KCP listener // Close our HTTP server and our KCP listener
l.closeOnce.Do(func() { l.closeOnce.Do(func() {
...@@ -235,14 +242,15 @@ func (l *SnowflakeListener) queueConn(conn net.Conn) error { ...@@ -235,14 +242,15 @@ func (l *SnowflakeListener) queueConn(conn net.Conn) error {
} }
} }
// A wrapper for the underlying oneshot or turbotunnel conn // SnowflakeClientConn is a wrapper for the underlying oneshot or turbotunnel
// because we need to reference our mapping to determine the client // conn. We need to reference our client address map to determine the
// address // remote address
type SnowflakeClientConn struct { type SnowflakeClientConn struct {
net.Conn net.Conn
address net.Addr address net.Addr
} }
// RemoteAddr returns the mapped client address of the Snowflake connection
func (conn *SnowflakeClientConn) RemoteAddr() net.Addr { func (conn *SnowflakeClientConn) RemoteAddr() net.Addr {
return conn.address return conn.address
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment