-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (43 loc) · 1.03 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
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/panjf2000/gnet/v2"
"github.com/spf13/pflag"
"github.com/shanexu/gnet-socks5/internel/logging"
"github.com/shanexu/gnet-socks5/pkg/net/socks5"
)
var (
bindAddr string
noAuth bool
username string
password string
)
func init() {
pflag.StringVarP(&bindAddr, "bind-addr", "b", ":1080", "bind address")
pflag.BoolVar(&noAuth, "no-auth", false, "disable authentication")
pflag.StringVar(&username, "username", "username", "username")
pflag.StringVar(&password, "password", "password", "password")
}
func main() {
pflag.Parse()
addr := fmt.Sprintf("tcp://%s", bindAddr)
if noAuth {
username = ""
password = ""
}
server := socks5.NewGNetServer(addr, username, password)
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
go func() {
err := gnet.Run(server, addr, gnet.WithMulticore(true), gnet.WithReuseAddr(true))
if err != nil {
logging.Fatal(err)
}
}()
<-sigCh
server.Stop(context.Background())
}