mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-07-22 05:24:29 +02:00
main, sshd: Add comments and TODOs
This commit is contained in:
parent
fe84822f5d
commit
fdfdcf96b7
4
host.go
4
host.go
@ -97,6 +97,10 @@ func (h *Host) Connect(term *sshd.Terminal) {
|
|||||||
cfg.Theme = &h.theme
|
cfg.Theme = &h.theme
|
||||||
user.SetConfig(cfg)
|
user.SetConfig(cfg)
|
||||||
|
|
||||||
|
// Load user config overrides from ENV
|
||||||
|
// TODO: Would be nice to skip the command parsing pipeline just to load
|
||||||
|
// config values. Would need to factor out some command handler logic into
|
||||||
|
// accessible helpers.
|
||||||
env := term.Env()
|
env := term.Env()
|
||||||
for _, e := range env {
|
for _, e := range env {
|
||||||
switch e.Key {
|
switch e.Key {
|
||||||
|
@ -93,6 +93,7 @@ type Terminal struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make new terminal from a session channel
|
// Make new terminal from a session channel
|
||||||
|
// TODO: For v2, make a separate `Serve(ctx context.Context) error` method to activate the Terminal
|
||||||
func NewTerminal(conn *ssh.ServerConn, ch ssh.NewChannel) (*Terminal, error) {
|
func NewTerminal(conn *ssh.ServerConn, ch ssh.NewChannel) (*Terminal, error) {
|
||||||
if ch.ChannelType() != "session" {
|
if ch.ChannelType() != "session" {
|
||||||
return nil, ErrNotSessionChannel
|
return nil, ErrNotSessionChannel
|
||||||
@ -131,15 +132,18 @@ func NewTerminal(conn *ssh.ServerConn, ch ssh.NewChannel) (*Terminal, error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// We need to wait for term.ready to acquire a shell before we return, this
|
||||||
|
// gives the SSH session a chance to populate the env vars and other state.
|
||||||
|
// TODO: Make the timeout configurable
|
||||||
|
// TODO: Use context.Context for abort/timeout in the future, will need to change the API.
|
||||||
select {
|
select {
|
||||||
case <-ready: // ok...
|
case <-ready: // shell acquired
|
||||||
|
return &term, nil
|
||||||
case <-term.done:
|
case <-term.done:
|
||||||
return nil, errors.New("terminal aborted")
|
return nil, errors.New("terminal aborted")
|
||||||
case <-time.NewTimer(time.Minute).C:
|
case <-time.NewTimer(time.Minute).C:
|
||||||
return nil, errors.New("timed out starting terminal")
|
return nil, errors.New("timed out starting terminal")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &term, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSession Finds a session channel and make a Terminal from it
|
// NewSession Finds a session channel and make a Terminal from it
|
||||||
@ -169,7 +173,7 @@ func (t *Terminal) Close() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Negotiate terminal type and settings
|
// listen negotiates the terminal type and state
|
||||||
// ready is closed when the terminal is ready.
|
// ready is closed when the terminal is ready.
|
||||||
func (t *Terminal) listen(requests <-chan *ssh.Request, ready chan<- struct{}) {
|
func (t *Terminal) listen(requests <-chan *ssh.Request, ready chan<- struct{}) {
|
||||||
hasShell := false
|
hasShell := false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user