|
|
@@ -10,26 +10,28 @@ import (
|
|
10
|
10
|
"github.com/juju/errors"
|
|
11
|
11
|
)
|
|
12
|
12
|
|
|
|
13
|
+// Config represents common configuration of mtg.
|
|
13
|
14
|
type Config struct {
|
|
14
|
|
- Debug bool
|
|
15
|
|
- Verbose bool
|
|
16
|
|
- BindIP net.IP
|
|
17
|
|
- BindPort uint16
|
|
|
15
|
+ Debug bool
|
|
|
16
|
+ Verbose bool
|
|
18
|
17
|
|
|
19
|
|
- PublicIPv4 net.IP
|
|
|
18
|
+ BindPort uint16
|
|
20
|
19
|
PublicIPv4Port uint16
|
|
21
|
|
- PublicIPv6 net.IP
|
|
22
|
20
|
PublicIPv6Port uint16
|
|
23
|
|
-
|
|
24
|
|
- StatsIP net.IP
|
|
25
|
|
- StatsPort uint16
|
|
|
21
|
+ StatsPort uint16
|
|
26
|
22
|
|
|
27
|
23
|
TimeoutRead time.Duration
|
|
28
|
24
|
TimeoutWrite time.Duration
|
|
29
|
25
|
|
|
|
26
|
+ BindIP net.IP
|
|
|
27
|
+ PublicIPv4 net.IP
|
|
|
28
|
+ PublicIPv6 net.IP
|
|
|
29
|
+ StatsIP net.IP
|
|
|
30
|
+
|
|
30
|
31
|
Secret []byte
|
|
31
|
32
|
}
|
|
32
|
33
|
|
|
|
34
|
+// URLs contains links to the proxy (tg://, t.me) and their QR codes.
|
|
33
|
35
|
type URLs struct {
|
|
34
|
36
|
TG string `json:"tg_url"`
|
|
35
|
37
|
TMe string `json:"tme_url"`
|
|
|
@@ -37,27 +39,33 @@ type URLs struct {
|
|
37
|
39
|
TMeQRCode string `json:"tme_qrcode"`
|
|
38
|
40
|
}
|
|
39
|
41
|
|
|
|
42
|
+// IPURLs contains links to both ipv4 and ipv6 of the proxy.
|
|
40
|
43
|
type IPURLs struct {
|
|
41
|
44
|
IPv4 URLs `json:"ipv4"`
|
|
42
|
45
|
IPv6 URLs `json:"ipv6"`
|
|
43
|
46
|
}
|
|
44
|
47
|
|
|
|
48
|
+// BindAddr returns connection for this server to bind to.
|
|
45
|
49
|
func (c *Config) BindAddr() string {
|
|
46
|
50
|
return getAddr(c.BindIP, c.BindPort)
|
|
47
|
51
|
}
|
|
48
|
52
|
|
|
|
53
|
+// IPv4Addr returns connection string to ipv6 for mtproto proxy.
|
|
49
|
54
|
func (c *Config) IPv4Addr() string {
|
|
50
|
55
|
return getAddr(c.PublicIPv4, c.PublicIPv4Port)
|
|
51
|
56
|
}
|
|
52
|
57
|
|
|
|
58
|
+// IPv6Addr returns connection string to ipv6 for mtproto proxy.
|
|
53
|
59
|
func (c *Config) IPv6Addr() string {
|
|
54
|
60
|
return getAddr(c.PublicIPv6, c.PublicIPv6Port)
|
|
55
|
61
|
}
|
|
56
|
62
|
|
|
|
63
|
+// StatAddr returns connection string to the stats API.
|
|
57
|
64
|
func (c *Config) StatAddr() string {
|
|
58
|
65
|
return getAddr(c.StatsIP, c.StatsPort)
|
|
59
|
66
|
}
|
|
60
|
67
|
|
|
|
68
|
+// GetURLs returns configured IPURLs instance with links to this server.
|
|
61
|
69
|
func (c *Config) GetURLs() IPURLs {
|
|
62
|
70
|
return IPURLs{
|
|
63
|
71
|
IPv4: getURLs(c.PublicIPv4, c.PublicIPv4Port, c.Secret),
|
|
|
@@ -69,7 +77,10 @@ func getAddr(host fmt.Stringer, port uint16) string {
|
|
69
|
77
|
return net.JoinHostPort(host.String(), strconv.Itoa(int(port)))
|
|
70
|
78
|
}
|
|
71
|
79
|
|
|
72
|
|
-func NewConfig(debug, verbose bool,
|
|
|
80
|
+// NewConfig returns new configuration. If required, it manages and
|
|
|
81
|
+// fetches data from external sources. Parameters passed to this
|
|
|
82
|
+// function, should come from command line arguments.
|
|
|
83
|
+func NewConfig(debug, verbose bool, // nolint: gocyclo
|
|
73
|
84
|
bindIP net.IP, bindPort uint16,
|
|
74
|
85
|
publicIPv4 net.IP, PublicIPv4Port uint16,
|
|
75
|
86
|
publicIPv6 net.IP, publicIPv6Port uint16,
|
|
|
@@ -120,6 +131,8 @@ func NewConfig(debug, verbose bool,
|
|
120
|
131
|
PublicIPv4Port: PublicIPv4Port,
|
|
121
|
132
|
PublicIPv6: publicIPv6,
|
|
122
|
133
|
PublicIPv6Port: publicIPv6Port,
|
|
|
134
|
+ StatsIP: statsIP,
|
|
|
135
|
+ StatsPort: statsPort,
|
|
123
|
136
|
TimeoutRead: timeoutRead,
|
|
124
|
137
|
TimeoutWrite: timeoutWrite,
|
|
125
|
138
|
Secret: secretBytes,
|