-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract client behaviour outside the main (#90)
The client's main function now only prepares the transport connection. It then instantiates and manipulates a Client object. This can be used to automatize behaviours and potentially lead to easy ProxyJump implementation (as asked by #44). * separate QUIC transport logic and user-auth/conversation logic * use of options and canonicalize hosts format * known hosts: design hosts by their canonical representation * do not log a non-zero exit status as an error
- Loading branch information
1 parent
aecfb89
commit 0790a5d
Showing
11 changed files
with
965 additions
and
743 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
) | ||
|
||
type Options struct { | ||
username string | ||
hostname string | ||
port int | ||
urlPath string | ||
authMethods []interface{} | ||
} | ||
|
||
func NewOptions(username string, hostname string, port int, urlPath string, authMethods []interface{}) (*Options, error) { | ||
if len(urlPath) == 0 || urlPath[0] != '/' { | ||
urlPath = "/" + urlPath | ||
} | ||
return &Options{ | ||
username: username, | ||
hostname: hostname, | ||
port: port, | ||
urlPath: urlPath, | ||
authMethods: authMethods, | ||
}, nil | ||
} | ||
|
||
func (o *Options) Username() string { | ||
return o.username | ||
} | ||
|
||
func (o *Options) Hostname() string { | ||
return o.hostname | ||
} | ||
|
||
// Returns the pair hostname:port in a valid URL format. | ||
// This means that an IPv6 will be written inside square brackets []. | ||
// examples: "127.0.0.1:443", "example.org:1234", "[::1]:22"" | ||
func (o *Options) URLHostnamePort() string { | ||
hostnameIsAnIP := net.ParseIP(o.hostname) != nil | ||
if hostnameIsAnIP { | ||
ip := net.ParseIP(o.hostname) | ||
if ip.To4() == nil && ip.To16() != nil { | ||
// enforce the square-bracketed notation for ipv6 UDP addresses | ||
return fmt.Sprintf("[%s]:%d", o.hostname, o.port) | ||
} | ||
} | ||
return fmt.Sprintf("%s:%d", o.hostname, o.port) | ||
} | ||
|
||
func (o *Options) Port() int { | ||
return o.port | ||
} | ||
func (o *Options) UrlPath() string { | ||
return o.urlPath | ||
} | ||
|
||
// Returns the canonical host representation used by SSH3. | ||
// The format is <urlhostnameport><path> | ||
// <urlhostnameport> is the host:port pair in the format returned by | ||
// URLHostnamePort() | ||
// <path> is the URL path, it always starts with a "/", it is therefore never empty. | ||
func (o *Options) CanonicalHostFormat() string { | ||
return fmt.Sprintf("%s:%d%s", o.hostname, o.port, o.urlPath) | ||
} | ||
|
||
func (o *Options) AuthMethods() []interface{} { | ||
return o.authMethods | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//go:build !windows | ||
|
||
package winsize | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
"unsafe" | ||
) | ||
|
||
func GetWinsize(tty *os.File) (ws WindowSize, err error) { | ||
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(tty.Fd()), uintptr(syscall.TIOCGWINSZ), | ||
uintptr(unsafe.Pointer(&ws))) | ||
if errno != 0 { | ||
err = errno | ||
} | ||
return ws, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.