|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+package cli
|
|
|
2
|
+
|
|
|
3
|
+import (
|
|
|
4
|
+ "fmt"
|
|
|
5
|
+ "net"
|
|
|
6
|
+ "strconv"
|
|
|
7
|
+ "time"
|
|
|
8
|
+
|
|
|
9
|
+ "github.com/9seconds/mtg/v2/internal/config"
|
|
|
10
|
+)
|
|
|
11
|
+
|
|
|
12
|
+type SimpleRun struct {
|
|
|
13
|
+ BindTo string `kong:"arg,required,name='bind-to',help='A host:port to bind proxy to.'"`
|
|
|
14
|
+ Secret string `kong:"arg,required,name='secret',help='Proxy secret.'"`
|
|
|
15
|
+
|
|
|
16
|
+ Debug bool `kong:"name='debug',short='d',help='Run in debug mode.'"`
|
|
|
17
|
+ Concurrency uint64 `kong:"name='concurrency',short='c',default='8192',help='Max number of concurrent connection to proxy.'"`
|
|
|
18
|
+ TCPBuffer string `kong:"name='tcp-buffer',short='b',default='4KB',help='Size of TCP buffer to use.'"`
|
|
|
19
|
+ PreferIP string `kong:"name='prefer-ip',short='i',default='prefer-ipv6',help='IP preference. By default we prefer IPv6 with fallback to IPv4.'"`
|
|
|
20
|
+ DomainFrontingPort uint64 `kong:"name='domain-fronting-port',short='p',default='443',help='A port to access for domain fronting.'"`
|
|
|
21
|
+ DOHIP net.IP `kong:"name='doh-ip',short='d',default='9.9.9.9',help='IP address of DNS-over-HTTP to use.'"`
|
|
|
22
|
+ Timeout time.Duration `kong:"name='timeout',short='t',default='10s',help='Network timeout to use'"`
|
|
|
23
|
+ AntiReplayCacheSize string `kong:"name='antireplay-cache-size',short='a',default='1MB',help='A size of anti-replay cache to use.'"`
|
|
|
24
|
+}
|
|
|
25
|
+
|
|
|
26
|
+func (s *SimpleRun) Run(cli *CLI, version string) error {
|
|
|
27
|
+ conf := &config.Config{}
|
|
|
28
|
+
|
|
|
29
|
+ if err := conf.BindTo.Set(s.BindTo); err != nil {
|
|
|
30
|
+ return fmt.Errorf("incorrect bind-to parameter: %w", err)
|
|
|
31
|
+ }
|
|
|
32
|
+
|
|
|
33
|
+ if err := conf.Secret.Set(s.Secret); err != nil {
|
|
|
34
|
+ return fmt.Errorf("incorrect secret: %w", err)
|
|
|
35
|
+ }
|
|
|
36
|
+
|
|
|
37
|
+ if err := conf.Concurrency.Set(strconv.FormatUint(s.Concurrency, 10)); err != nil {
|
|
|
38
|
+ return fmt.Errorf("incorrect concurrency: %w", err)
|
|
|
39
|
+ }
|
|
|
40
|
+
|
|
|
41
|
+ if err := conf.TCPBuffer.Set(s.TCPBuffer); err != nil {
|
|
|
42
|
+ return fmt.Errorf("incorrect tcp-buffer: %w", err)
|
|
|
43
|
+ }
|
|
|
44
|
+
|
|
|
45
|
+ if err := conf.PreferIP.Set(s.PreferIP); err != nil {
|
|
|
46
|
+ return fmt.Errorf("incorrect prefer-ip: %w", err)
|
|
|
47
|
+ }
|
|
|
48
|
+
|
|
|
49
|
+ if err := conf.DomainFrontingPort.Set(strconv.FormatUint(s.DomainFrontingPort, 10)); err != nil {
|
|
|
50
|
+ return fmt.Errorf("incorrect domain-fronting-port: %w", err)
|
|
|
51
|
+ }
|
|
|
52
|
+
|
|
|
53
|
+ if err := conf.Network.DOHIP.Set(s.DOHIP.String()); err != nil {
|
|
|
54
|
+ return fmt.Errorf("incorrect doh-ip: %w", err)
|
|
|
55
|
+ }
|
|
|
56
|
+
|
|
|
57
|
+ if err := conf.Network.Timeout.TCP.Set(s.Timeout.String()); err != nil {
|
|
|
58
|
+ return fmt.Errorf("incorrect timeout: %w", err)
|
|
|
59
|
+ }
|
|
|
60
|
+
|
|
|
61
|
+ if err := conf.Network.Timeout.HTTP.Set(s.Timeout.String()); err != nil {
|
|
|
62
|
+ return fmt.Errorf("incorrect timeout: %w", err)
|
|
|
63
|
+ }
|
|
|
64
|
+
|
|
|
65
|
+ if err := conf.Network.Timeout.Idle.Set(s.Timeout.String()); err != nil {
|
|
|
66
|
+ return fmt.Errorf("incorrect timeout: %w", err)
|
|
|
67
|
+ }
|
|
|
68
|
+
|
|
|
69
|
+ if err := conf.Defense.AntiReplay.MaxSize.Set(s.AntiReplayCacheSize); err != nil {
|
|
|
70
|
+ return fmt.Errorf("incorrect antireplay-cache-size: %w", err)
|
|
|
71
|
+ }
|
|
|
72
|
+
|
|
|
73
|
+ conf.Debug.Value = s.Debug
|
|
|
74
|
+ conf.Defense.AntiReplay.Enabled.Value = true
|
|
|
75
|
+ conf.Defense.Blocklist.Enabled.Value = false
|
|
|
76
|
+ conf.Stats.StatsD.Enabled.Value = false
|
|
|
77
|
+ conf.Stats.Prometheus.Enabled.Value = false
|
|
|
78
|
+
|
|
|
79
|
+ if err := conf.Validate(); err != nil {
|
|
|
80
|
+ return fmt.Errorf("invalid result configuration: %w", err)
|
|
|
81
|
+ }
|
|
|
82
|
+
|
|
|
83
|
+ return runProxy(conf, version)
|
|
|
84
|
+}
|