-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
79 lines (67 loc) · 1.88 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"flag"
"fmt"
"github.com/VeeSecurity/SOCKS5Engine/socks5"
"io/ioutil"
"log"
"net"
"os"
"os/signal"
"syscall"
"time"
)
var conf config
func listenForSIGUSR1(srv *socks5.Server) {
sig := make(chan os.Signal)
signal.Notify(sig, syscall.SIGUSR1)
for {
<-sig
queue, authenticators, reqHandlers := srv.GetCurrentData()
log.Println(
fmt.Sprintf("\n"),
fmt.Sprintf("Connection queue: %d\n", queue),
fmt.Sprintf("Idle authenticators: %d\n", authenticators),
fmt.Sprintf("Idle reqhandlers: %d\n", reqHandlers))
}
}
func main() {
const confMessage = "Full path to config. Refer to default config.conf for an example."
v := flag.Bool("v", false, "version")
h := flag.Bool("h", false, "help")
pathToConfig := flag.String("conf", "/etc/vee-socks5/config.conf", confMessage)
flag.Parse()
if *v {
log.Panic(version)
}
if *h {
log.Panic(help)
}
parseConfig(*pathToConfig)
authProto, authNoneAllowed := generateAuthFuncPrototype()
authFunc, startCallback, endCallback := setRedis(authProto)
checkIP := generateCheckIP()
localIP := net.ParseIP(conf.LocalIP)
setRuntime()
srv := &socks5.Server{
Port: conf.Port,
NumAuthWorkers: conf.Authenticators,
NumReqHandleWorkers: conf.ReqHandlers,
ConnQueueSize: conf.ConnectionQueueSize,
BufferSize: conf.BufferSize,
ConnTimeLimit: time.Duration(conf.ConnLifetime) * time.Second,
HandshakeStepTimeLimit: time.Duration(conf.HandshakeStepTimeout) * time.Second,
CheckIP: checkIP,
AuthMethodNoneAllowed: authNoneAllowed,
Authenticate: authFunc,
SessionStartCallback: startCallback,
SessionEndCallback: endCallback,
LocalIP: localIP,
}
if !conf.Logging {
srv.SetLogger(log.New(ioutil.Discard, "", 0))
}
log.Println("running VPE")
go listenForSIGUSR1(srv)
srv.ListenAndServe()
}