mirror of
https://github.com/cirruslabs/orchard.git
synced 2026-10-01 12:32:11 +02:00
* 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.
47 lines
889 B
Go
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
|
|
}
|