// Listen requests the remote peer open a listening socket on // addr. Incoming connections will be available by calling Accept on // the returned net.Listener. The listener must be serviced, or the // SSH connection may hang. // N must be "tcp", "tcp4", "tcp6", or "unix". func (c *Client) Listen(n, addr string) (net.Listener, error) { … } const openSSHPrefix … var portRandomizer … // isBrokenOpenSSHVersion returns true if the given version string // specifies a version of OpenSSH that is known to have a bug in port // forwarding. func isBrokenOpenSSHVersion(versionStr string) bool { … } // autoPortListenWorkaround simulates automatic port allocation by // trying random ports repeatedly. func (c *Client) autoPortListenWorkaround(laddr *net.TCPAddr) (net.Listener, error) { … } type channelForwardMsg … // handleForwards starts goroutines handling forwarded connections. // It's called on first use by (*Client).ListenTCP to not launch // goroutines until needed. func (c *Client) handleForwards() { … } // ListenTCP requests the remote peer open a listening socket // on laddr. Incoming connections will be available by calling // Accept on the returned net.Listener. func (c *Client) ListenTCP(laddr *net.TCPAddr) (net.Listener, error) { … } type forwardList … type forwardEntry … type forward … func (l *forwardList) add(addr net.Addr) chan forward { … } type forwardedTCPPayload … // parseTCPAddr parses the originating address from the remote into a *net.TCPAddr. func parseTCPAddr(addr string, port uint32) (*net.TCPAddr, error) { … } func (l *forwardList) handleChannels(in <-chan NewChannel) { … } // remove removes the forward entry, and the channel feeding its // listener. func (l *forwardList) remove(addr net.Addr) { … } // closeAll closes and clears all forwards. func (l *forwardList) closeAll() { … } func (l *forwardList) forward(laddr, raddr net.Addr, ch NewChannel) bool { … } type tcpListener … // Accept waits for and returns the next connection to the listener. func (l *tcpListener) Accept() (net.Conn, error) { … } // Close closes the listener. func (l *tcpListener) Close() error { … } // Addr returns the listener's network address. func (l *tcpListener) Addr() net.Addr { … } // DialContext initiates a connection to the addr from the remote host. // // The provided Context must be non-nil. If the context expires before the // connection is complete, an error is returned. Once successfully connected, // any expiration of the context will not affect the connection. // // See func Dial for additional information. func (c *Client) DialContext(ctx context.Context, n, addr string) (net.Conn, error) { … } // Dial initiates a connection to the addr from the remote host. // The resulting connection has a zero LocalAddr() and RemoteAddr(). func (c *Client) Dial(n, addr string) (net.Conn, error) { … } // DialTCP connects to the remote address raddr on the network net, // which must be "tcp", "tcp4", or "tcp6". If laddr is not nil, it is used // as the local address for the connection. func (c *Client) DialTCP(n string, laddr, raddr *net.TCPAddr) (net.Conn, error) { … } type channelOpenDirectMsg … func (c *Client) dial(laddr string, lport int, raddr string, rport int) (Channel, error) { … } type tcpChan … type chanConn … // LocalAddr returns the local network address. func (t *chanConn) LocalAddr() net.Addr { … } // RemoteAddr returns the remote network address. func (t *chanConn) RemoteAddr() net.Addr { … } // SetDeadline sets the read and write deadlines associated // with the connection. func (t *chanConn) SetDeadline(deadline time.Time) error { … } // SetReadDeadline sets the read deadline. // A zero value for t means Read will not time out. // After the deadline, the error from Read will implement net.Error // with Timeout() == true. func (t *chanConn) SetReadDeadline(deadline time.Time) error { … } // SetWriteDeadline exists to satisfy the net.Conn interface // but is not implemented by this type. It always returns an error. func (t *chanConn) SetWriteDeadline(deadline time.Time) error { … }