Files
orchard/internal/proxy/proxy.go
T
Nikolay Edigaryev d59bc7f8a7 Orchard Controller: implement an SSH server that acts as a jump host (#179)
* proxy.Connections(): require io.ReadWriteCloser instead of net.Conn

* Orchard Controller: implement an SSH server that acts as a jump host

* Issue a warning if the name used will be invalid in the future

* Further restrict uppercase characters in names in the future

The rationale is similar to https://github.com/kubernetes/kubernetes/issues/71140.

We won't want to munge the user's input and introduce subtle bugs doing
lowercase comparisons.
2024-06-11 19:32:45 +04:00

47 lines
889 B
Go

package proxy
import (
"io"
"strings"
)
func Connections(left io.ReadWriteCloser, right io.ReadWriteCloser) (finalErr error) {
leftErrCh := make(chan error, 1)
rightErrCh := make(chan error, 1)
recordErr := func(newErr error) {
if newErr != nil && finalErr == nil {
finalErr = newErr
}
}
go func() {
_, err := io.Copy(left, right)
rightErrCh <- err
}()
go func() {
_, err := io.Copy(right, left)
leftErrCh <- err
}()
// Wait for some goroutine and then unlock the other goroutine
// by closing its source io.Reader
select {
case err := <-rightErrCh:
recordErr(err)
recordErr(left.Close())
recordErr(<-leftErrCh)
case err := <-leftErrCh:
recordErr(err)
recordErr(right.Close())
recordErr(<-rightErrCh)
}
if finalErr != nil && strings.Contains(finalErr.Error(), "use of closed network connection") {
finalErr = nil
}
return finalErr
}