mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-01 14:05:39 +00:00
71029cea2d
This updates all source files to use a new standard header for copyright and license declaration. Notably, copyright no longer includes a date, and we now use the standard SPDX-License-Identifier header. This commit was done almost entirely mechanically with perl, and then some minimal manual fixes. Updates #6865 Signed-off-by: Will Norris <will@tailscale.com>
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package tailssh
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
// sshContext is the context.Context implementation we use for SSH
|
|
// that adds a CloseWithError method. Otherwise it's just a normalish
|
|
// Context.
|
|
type sshContext struct {
|
|
underlying context.Context
|
|
cancel context.CancelFunc // cancels underlying
|
|
mu sync.Mutex
|
|
closed bool
|
|
err error
|
|
}
|
|
|
|
func newSSHContext(ctx context.Context) *sshContext {
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
return &sshContext{underlying: ctx, cancel: cancel}
|
|
}
|
|
|
|
func (ctx *sshContext) CloseWithError(err error) {
|
|
ctx.mu.Lock()
|
|
defer ctx.mu.Unlock()
|
|
if ctx.closed {
|
|
return
|
|
}
|
|
ctx.closed = true
|
|
ctx.err = err
|
|
ctx.cancel()
|
|
}
|
|
|
|
func (ctx *sshContext) Err() error {
|
|
ctx.mu.Lock()
|
|
defer ctx.mu.Unlock()
|
|
return ctx.err
|
|
}
|
|
|
|
func (ctx *sshContext) Done() <-chan struct{} { return ctx.underlying.Done() }
|
|
func (ctx *sshContext) Deadline() (deadline time.Time, ok bool) { return }
|
|
func (ctx *sshContext) Value(k any) any { return ctx.underlying.Value(k) }
|
|
|
|
// userVisibleError is a wrapper around an error that implements
|
|
// SSHTerminationError, so msg is written to their session.
|
|
type userVisibleError struct {
|
|
msg string
|
|
error
|
|
}
|
|
|
|
func (ue userVisibleError) SSHTerminationMessage() string { return ue.msg }
|
|
|
|
// SSHTerminationError is implemented by errors that terminate an SSH
|
|
// session and should be written to user's sessions.
|
|
type SSHTerminationError interface {
|
|
error
|
|
SSHTerminationMessage() string
|
|
}
|