-
Notifications
You must be signed in to change notification settings - Fork 0
/
transfer.go
55 lines (46 loc) · 1.26 KB
/
transfer.go
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
52
53
54
55
package sockstrans
import (
"github.com/wsrf16/swiss/netkit/layer/transport/tcptrans"
"github.com/wsrf16/swiss/sugar/io/iokit"
"golang.org/x/net/proxy"
"net"
"os"
"os/signal"
"syscall"
)
type SocksTransferContext struct {
LAddr *net.TCPAddr
DAddr *net.TCPAddr
KeepListening bool
LListener *net.TCPListener
DListener *net.TCPListener
StopChan *chan os.Signal
}
func BuildTransfer(lAddress string, keepListening bool) (*SocksTransferContext, error) {
lAddr, err := tcptrans.NewTCPAddr(lAddress)
if err != nil {
return nil, err
}
stopChan := make(chan os.Signal, 1)
signal.Notify(stopChan,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
return &SocksTransferContext{LAddr: lAddr, KeepListening: keepListening, StopChan: &stopChan}, nil
}
func (t SocksTransferContext) Stop() {
*t.StopChan <- os.Interrupt
iokit.Close(t.LListener, t.DListener)
}
func (t SocksTransferContext) GetLListener() *net.TCPListener {
return t.LListener
}
func (t SocksTransferContext) GetDListener() *net.TCPListener {
return t.DListener
}
func (t SocksTransferContext) TransferFromListen(auth *proxy.Auth) error {
lAddr := t.LAddr
keepListening := t.KeepListening
return TransferFromListen(lAddr, auth, keepListening, &t)
}