-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (53 loc) · 1.47 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
package main
import (
"flag"
"io/ioutil"
"log"
"os"
"os/signal"
"syscall"
"github.com/raydcast/socxy-go/proxy"
"gopkg.in/yaml.v2"
)
type Config struct {
Server struct {
Ports []int `yaml:"ports"`
Certificate struct {
RSABits int `yaml:"rsa_bits"`
Duration int `yaml:"duration"`
SNI string `yaml:"sni"`
} `yaml:"certificate"`
} `yaml:"server"`
UDPGW struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
MaxClients int `yaml:"max_clients"`
MaxConnectionsForClient int `yaml:"max_connections_for_client"`
} `yaml:"udpgw"`
}
func main() {
var (
configPath string
config Config
)
flag.StringVar(&configPath, "config", "config.yaml", "Socxy configuration filename")
flag.Parse()
configFile, err := ioutil.ReadFile(configPath)
if err != nil {
log.Fatalf("Error to open config file: %v", err)
}
if err := yaml.Unmarshal(configFile, &config); err != nil {
log.Fatalf("%v", err)
}
cert := proxy.NewCert(config.Server.Certificate.RSABits,
config.Server.Certificate.Duration, config.Server.Certificate.SNI)
for _, port := range config.Server.Ports {
go listen(port, cert)
log.Printf("Listening server on port: %v", port)
}
go udpgw_listen(config.UDPGW.Host, int64(config.UDPGW.Port),
int64(config.UDPGW.MaxClients), int64(config.UDPGW.MaxConnectionsForClient))
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
<-sigCh
}