Skip to content

Commit

Permalink
Revert "passive tunnel termination"
Browse files Browse the repository at this point in the history
This reverts commit bf1d0d6.
  • Loading branch information
xtaci committed Mar 16, 2018
1 parent b2390a5 commit 03f27ec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
19 changes: 12 additions & 7 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"math/rand"
"net"
"os"
"sync"
"time"

"golang.org/x/crypto/pbkdf2"
Expand Down Expand Up @@ -69,12 +68,18 @@ func handleClient(sess *smux.Session, p1 io.ReadWriteCloser, quiet bool) {
}
defer p2.Close()

// tunnel setup
var wg sync.WaitGroup
wg.Add(2)
go func() { io.Copy(p1, p2); wg.Done() }()
go func() { io.Copy(p2, p1); wg.Done() }()
wg.Wait()
// start tunnel
p1die := make(chan struct{})
go func() { io.Copy(p1, p2); close(p1die) }()

p2die := make(chan struct{})
go func() { io.Copy(p2, p1); close(p2die) }()

// wait for tunnel termination
select {
case <-p1die:
case <-p2die:
}
}

func checkError(err error) {
Expand Down
19 changes: 12 additions & 7 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"net/http"
_ "net/http/pprof"
"os"
"sync"
"time"

"golang.org/x/crypto/pbkdf2"
Expand Down Expand Up @@ -94,12 +93,18 @@ func handleClient(p1, p2 io.ReadWriteCloser, quiet bool) {
defer p1.Close()
defer p2.Close()

// tunnel setup
var wg sync.WaitGroup
wg.Add(2)
go func() { io.Copy(p1, p2); wg.Done() }()
go func() { io.Copy(p2, p1); wg.Done() }()
wg.Wait()
// start tunnel
p1die := make(chan struct{})
go func() { io.Copy(p1, p2); close(p1die) }()

p2die := make(chan struct{})
go func() { io.Copy(p2, p1); close(p2die) }()

// wait for tunnel termination
select {
case <-p1die:
case <-p2die:
}
}

func checkError(err error) {
Expand Down

0 comments on commit 03f27ec

Please sign in to comment.