-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxy.go
More file actions
51 lines (41 loc) · 747 Bytes
/
proxy.go
File metadata and controls
51 lines (41 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package tcpdam
import (
"io"
"sync"
"github.com/op/go-logging"
)
type Proxy struct {
Lconn, Rconn io.ReadWriteCloser
Dam *Dam
Logger *logging.Logger
}
func (p *Proxy) Flush() error {
p.Logger.Debug("Flush connection")
defer p.Lconn.Close()
defer p.Dam.Flushed(p)
Rconn, err := p.Dam.Dial()
if err != nil {
return err
}
p.Rconn = Rconn
defer p.Rconn.Close()
var wg sync.WaitGroup
wg.Add(1)
go func() {
io.Copy(p.Lconn, p.Rconn)
p.Lconn.Close()
wg.Done()
}()
wg.Add(1)
go func() {
io.Copy(p.Rconn, p.Lconn)
p.Rconn.Close()
wg.Done()
}()
wg.Wait()
p.Logger.Debug("Flushing connection done")
return nil
}
func (p *Proxy) Start() {
// Should slowly read and buffer Lconn to not timeout
}