-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_run.go
78 lines (60 loc) · 3.34 KB
/
simple_run.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
package cli
import (
"fmt"
"net"
"strconv"
"time"
"github.com/eyedeekay/mtg-i2p/internal/config"
)
type SimpleRun struct {
BindTo string `kong:"arg,required,name='bind-to',help='A host:port to bind proxy to.'"`
Secret string `kong:"arg,required,name='secret',help='Proxy secret.'"`
Debug bool `kong:"name='debug',short='d',help='Run in debug mode.'"` // nolint: lll
Concurrency uint64 `kong:"name='concurrency',short='c',default='8192',help='Max number of concurrent connection to proxy.'"` // nolint: lll
TCPBuffer string `kong:"name='tcp-buffer',short='b',default='4KB',help='Deprecated and ignored'"` // nolint: lll
PreferIP string `kong:"name='prefer-ip',short='i',default='prefer-ipv6',help='IP preference. By default we prefer IPv6 with fallback to IPv4.'"` // nolint: lll
DomainFrontingPort uint64 `kong:"name='domain-fronting-port',short='p',default='443',help='A port to access for domain fronting.'"` // nolint: lll
DOHIP net.IP `kong:"name='doh-ip',short='n',default='9.9.9.9',help='IP address of DNS-over-HTTP to use.'"` // nolint: lll
Timeout time.Duration `kong:"name='timeout',short='t',default='10s',help='Network timeout to use'"` // nolint: lll
AntiReplayCacheSize string `kong:"name='antireplay-cache-size',short='a',default='1MB',help='A size of anti-replay cache to use.'"` // nolint: lll
}
func (s *SimpleRun) Run(cli *CLI, version string) error { // nolint: cyclop
conf := &config.Config{}
if err := conf.BindTo.Set(s.BindTo); err != nil {
return fmt.Errorf("incorrect bind-to parameter: %w", err)
}
if err := conf.Secret.Set(s.Secret); err != nil {
return fmt.Errorf("incorrect secret: %w", err)
}
if err := conf.Concurrency.Set(strconv.FormatUint(s.Concurrency, 10)); err != nil { // nolint: gomnd
return fmt.Errorf("incorrect concurrency: %w", err)
}
if err := conf.PreferIP.Set(s.PreferIP); err != nil {
return fmt.Errorf("incorrect prefer-ip: %w", err)
}
if err := conf.DomainFrontingPort.Set(strconv.FormatUint(s.DomainFrontingPort, 10)); err != nil { // nolint: gomnd
return fmt.Errorf("incorrect domain-fronting-port: %w", err)
}
if err := conf.Network.DOHIP.Set(s.DOHIP.String()); err != nil {
return fmt.Errorf("incorrect doh-ip: %w", err)
}
if err := conf.Network.Timeout.TCP.Set(s.Timeout.String()); err != nil {
return fmt.Errorf("incorrect timeout: %w", err)
}
if err := conf.Network.Timeout.HTTP.Set(s.Timeout.String()); err != nil {
return fmt.Errorf("incorrect timeout: %w", err)
}
if err := conf.Network.Timeout.Idle.Set(s.Timeout.String()); err != nil {
return fmt.Errorf("incorrect timeout: %w", err)
}
if err := conf.Defense.AntiReplay.MaxSize.Set(s.AntiReplayCacheSize); err != nil {
return fmt.Errorf("incorrect antireplay-cache-size: %w", err)
}
conf.Debug.Value = s.Debug
conf.AllowFallbackOnUnknownDC.Value = true
conf.Defense.AntiReplay.Enabled.Value = true
if err := conf.Validate(); err != nil {
return fmt.Errorf("invalid result configuration: %w", err)
}
return runProxy(conf, version)
}