Skip to content

Commit

Permalink
Better handle connection proxying
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniomika committed Nov 24, 2019
1 parent 8a3577e commit 05308c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func handleAlias(newChannel ssh.NewChannel, sshConn *SSHConnection, state *State

sshConn.Listeners.Store(conn.RemoteAddr(), nil)

copyBoth(conn, connection, false)
copyBoth(conn, connection, true)
sshConn.CleanUp(state)
}

Expand Down
29 changes: 14 additions & 15 deletions requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func handleRemoteForward(newRequest *ssh.Request, sshConn *SSHConnection, state
}
}

go copyBoth(cl, newChan, false)
go copyBoth(cl, newChan, true)
go ssh.DiscardRequests(newReqs)
}
}
Expand All @@ -245,30 +245,29 @@ func copyBoth(writer net.Conn, reader ssh.Channel, wait bool) {
if wait {
wg.Add(1)
defer wg.Done()
} else {
defer closeBoth()
}

_, err := io.Copy(writer, reader)
if err != nil && *debug {
log.Println("Error writing to reader:", err)
log.Println("Error writing to writer:", err)
}
}()

if wait {
wg.Add(1)
} else {
defer closeBoth()
}
go func() {
if wait {
wg.Add(1)
defer wg.Done()
}

_, err := io.Copy(reader, writer)
if err != nil && *debug {
log.Println("Error writing to reader:", err)
}
}()

_, err := io.Copy(reader, writer)
if err != nil && *debug {
log.Println("Error writing to writer:", err)
}
if wait {
wg.Done()
wg.Wait()
}

wg.Wait()
closeBoth()
}

0 comments on commit 05308c0

Please sign in to comment.