Преглед изворни кода

Document environment variables

tags/0.11
9seconds пре 7 година
родитељ
комит
8906ae0db0
2 измењених фајлова са 61 додато и 28 уклоњено
  1. 48
    15
      README.md
  2. 13
    13
      main.go

+ 48
- 15
README.md Прегледај датотеку

5
 [![Build Status](https://travis-ci.org/9seconds/mtg.svg?branch=master)](https://travis-ci.org/9seconds/mtg)
5
 [![Build Status](https://travis-ci.org/9seconds/mtg.svg?branch=master)](https://travis-ci.org/9seconds/mtg)
6
 [![Docker Build Status](https://img.shields.io/docker/build/nineseconds/mtg.svg)](https://hub.docker.com/r/nineseconds/mtg/)
6
 [![Docker Build Status](https://img.shields.io/docker/build/nineseconds/mtg.svg)](https://hub.docker.com/r/nineseconds/mtg/)
7
 
7
 
8
-
9
 # Rationale
8
 # Rationale
10
 
9
 
11
 There are several available proxies for Telegram MTPROTO available. Here
10
 There are several available proxies for Telegram MTPROTO available. Here
60
 # How to build
59
 # How to build
61
 
60
 
62
 ```console
61
 ```console
63
-$ make
62
+make
64
 ```
63
 ```
65
 
64
 
66
 If you want to build for another platform:
65
 If you want to build for another platform:
67
 
66
 
68
 ```console
67
 ```console
69
-$ make crosscompile
68
+make crosscompile
70
 ```
69
 ```
71
 
70
 
72
 If you want to build Docker image (called `mtg`):
71
 If you want to build Docker image (called `mtg`):
73
 
72
 
74
 ```console
73
 ```console
75
-$ make docker
74
+make docker
76
 ```
75
 ```
77
 
76
 
78
 # Docker image
77
 # Docker image
84
 - tags are for tagged releases
83
 - tags are for tagged releases
85
 
84
 
86
 ```console
85
 ```console
87
-$ docker pull nineseconds/mtg:latest
86
+docker pull nineseconds/mtg:latest
88
 ```
87
 ```
89
 
88
 
90
 ```console
89
 ```console
91
-$ docker pull nineseconds/mtg:stable
90
+docker pull nineseconds/mtg:stable
92
 ```
91
 ```
93
 
92
 
94
 ```console
93
 ```console
95
-$ docker pull nineseconds/mtg:0.10
94
+docker pull nineseconds/mtg:0.10
96
 ```
95
 ```
97
 
96
 
98
 # Configuration
97
 # Configuration
102
 First, you need to generate a secret:
101
 First, you need to generate a secret:
103
 
102
 
104
 ```console
103
 ```console
105
-$ openssl rand -hex 16
104
+openssl rand -hex 16
106
 ```
105
 ```
107
 
106
 
108
 or
107
 or
109
 
108
 
110
 ```console
109
 ```console
111
-$ head -c 512 /dev/urandom | md5sum | cut -f 1 -d ' '
110
+head -c 512 /dev/urandom | md5sum | cut -f 1 -d ' '
112
 ```
111
 ```
113
 
112
 
114
 ## Secure mode
113
 ## Secure mode
122
 Oneliners to generate such secrets:
121
 Oneliners to generate such secrets:
123
 
122
 
124
 ```console
123
 ```console
125
-$ echo dd$(openssl rand -hex 16)
124
+echo dd$(openssl rand -hex 16)
126
 ```
125
 ```
127
 
126
 
128
 or
127
 or
129
 
128
 
130
 ```console
129
 ```console
131
-$ echo dd$(head -c 512 /dev/urandom | md5sum | cut -f 1 -d ' ')
130
+echo dd$(head -c 512 /dev/urandom | md5sum | cut -f 1 -d ' ')
132
 ```
131
 ```
133
 
132
 
133
+## Environment variables
134
+
135
+It is possible to configure this tool using environment variables. You
136
+can configure any flag but not secret or adtag. Here is the list of
137
+supported environment variables:
138
+
139
+| Environment variable     | Corresponding flags    | Default value                     | Description                                                                                                                                                                                                                                                                |
140
+|--------------------------|------------------------|-----------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
141
+| `MTG_DEBUG               | `-d`, `--debug`        | `false`                           | Run in debug mode. Usually, you need to run in this mode  only if you develop this tool or its maintainer is asking you to provide  logs with such verbosity.                                                                                                              |
142
+| `MTG_VERBOSE`            | `-v`, `--verbose`      | `false`                           | Run in verbose mode. This is way less chatty than debug mode.                                                                                                                                                                                                              |
143
+| `MTG_IP`                 | `-b`, `--bind-ip`      | `127.0.0.1`                       | Which IP should we bind to. As usual, `0.0.0.0` means that we want to listen on all interfaces. Also, 4 zeroes will bind to both IPv4 and IPv6.                                                                                                                            |
144
+| `MTG_PORT`               | `-p`, `--bind-port`    | `3128`                            | Which port should we bind to (listen on).                                                                                                                                                                                                                                  |
145
+| `MTG_IPV4`               | `-4`, `--public-ipv4`  | [Autodetect](https://ifconfig.co) | IPv4 address of this proxy. This is required if you NAT your proxy or run it in a docker container. In that case, you absolutely need to specify public IPv4 address of the proxy, otherwise either URLs will be broken or proxy could not access Telegram middle proxies. |
146
+| `MTG_IPV4_PORT`          | `--public-ipv4-port`   | Value of `--bind-port`            | Which port should be public of IPv4 interface. This affects only generated links and should be changed only if you NAT your proxy or run it in a docker container.                                                                                                         |
147
+| `MTG_IPV6`               | `-6`, `--public-ipv6`  | [Autodetect](https://ifconfig.co) | IPv6 address of this proxy. This is required if you NAT your proxy or run it in a docker container. In that case, you absolutely need to specify public IPv6 address of the proxy, otherwise either URLs will be broken or proxy could not access Telegram middle proxies. |
148
+| `MTG_IPV6_PORT`          | `--public-ipv6-port`   | Value of `--bind-port`            | Which port should be public of IPv6 interface. This affects only generated links and should be changed only if you NAT your proxy or run it in a docker container.                                                                                                         |
149
+| `MTG_STATS_IP`           | `-t`, `--stats-ip`     | `127.0.0.1`                       | Which IP should we bind the internal statistics HTTP server.                                                                                                                                                                                                               |
150
+| `MTG_STATS_PORT`         | `-q`, `--stats-port`   | `3129`                            | Which port should we bind the internal statistics HTTP server.                                                                                                                                                                                                             |
151
+| `MTG_STATSD_IP`          | `--statsd-ip`          |                                   | IP/host addresses of statsd service. No defaults, by defaults we do not send anything there.                                                                                                                                                                               |
152
+| `MTG_STATSD_PORT`        | `--statsd-port`        | `8125`                            | Which port should we use to work with statsd.                                                                                                                                                                                                                              |
153
+| `MTG_STATSD_NETWORK`     | `--statsd-network`     | `udp`                             | Which protocol should we use to work with statsd. Possible options are `udp` and `tcp`.                                                                                                                                                                                    |
154
+| `MTG_STATSD_PREFIX`      | `--statsd-prefix`      | `mtg`                             | Which bucket prefix we should use. For example, if you set `mtg`, then metric `traffic.ingress` would be send as `mtg.traffic.ingress`.                                                                                                                                    |
155
+| `MTG_STATSD_TAGS_FORMAT` | `--statsd-tags-format` |                                   | Which tags format we should use. By default, we are using default vanilla statsd tags format but if you want to send directly to InfluxDB or Datadog, please specify it there. Possible options are `influxdb` and `datadog`.                                              |
156
+| `MTG_STATSD_TAGS`        | `--statsd-tags`        |                                   | Which tags should we send to statsd with our metrics. Please specify them as `key=value` pairs.                                                                                                                                                                            |
157
+| `MTG_BUFFER_WRITE`       | `-w`, `--write-buffer` | `65536`                           | The size of TCP write buffer in bytes. Write buffer is the buffer for messages which are going from client to Telegram.                                                                                                                                                    |
158
+| `MTG_BUFFER_READ`        | `-r`, `--read-buffer`  | `131072`                          | The size of TCP read buffer in bytes. Read buffer is the buffer for messages from Telegram to client.                                                                                                                                                                      |
159
+
160
+Usually you want to modify only read/write buffer sizes. If you feel
161
+that proxy is slow, try to increase both sizes giving more priority to
162
+read buffer.
163
+
164
+Unfortunately, MTPROTO proxy protocol does not allow us to use splice
165
+or any other neat tricks how to eliminate the need of copying data into
166
+userspace.
134
 
167
 
135
 # How to run the tool
168
 # How to run the tool
136
 
169
 
137
 Now run the tool:
170
 Now run the tool:
138
 
171
 
139
 ```console
172
 ```console
140
-$ mtg <secret>
173
+mtg <secret>
141
 ```
174
 ```
142
 
175
 
143
 How to run the tool with ADTag:
176
 How to run the tool with ADTag:
144
 
177
 
145
 ```console
178
 ```console
146
-$ mtg <secret> <adtag>
179
+mtg <secret> <adtag>
147
 ```
180
 ```
148
 
181
 
149
 This tool will listen on port 3128 by default with the given secret.
182
 This tool will listen on port 3128 by default with the given secret.
151
 # One-line runner
184
 # One-line runner
152
 
185
 
153
 ```console
186
 ```console
154
-$ docker run --name mtg --restart=unless-stopped -p 3128:3128 -p 3129:3129 -d nineseconds/mtg:stable $(openssl rand -hex 16)
187
+docker run --name mtg --restart=unless-stopped -p 3128:3128 -p 3129:3129 -d nineseconds/mtg:stable $(openssl rand -hex 16)
155
 ```
188
 ```
156
 
189
 
157
 or in secret mode:
190
 or in secret mode:
158
 
191
 
159
 ```console
192
 ```console
160
-$ docker run --name mtg --restart=unless-stopped -p 3128:3128 -p 3129:3129 -d nineseconds/mtg:stable dd$(openssl rand -hex 16)
193
+docker run --name mtg --restart=unless-stopped -p 3128:3128 -p 3129:3129 -d nineseconds/mtg:stable dd$(openssl rand -hex 16)
161
 ```
194
 ```
162
 
195
 
163
 You will have this tool up and running on port 3128. Now curl
196
 You will have this tool up and running on port 3128. Now curl

+ 13
- 13
main.go Прегледај датотеку

49
 		Default("3128").
49
 		Default("3128").
50
 		Uint16()
50
 		Uint16()
51
 
51
 
52
-	writeBufferSize = app.Flag("write-buffer",
53
-		"Write buffer size in bytes. You can think about it as a buffer from client to Telegram.").
54
-		Short('w').
55
-		Envar("MTG_BUFFER_WRITE").
56
-		Default("65536").
57
-		Uint32()
58
-	readBufferSize = app.Flag("read-buffer",
59
-		"Read buffer size in bytes. You can think about it as a buffer from Telegram to client.").
60
-		Short('r').
61
-		Envar("MTG_BUFFER_READ").
62
-		Default("131072").
63
-		Uint32()
64
-
65
 	publicIPv4 = app.Flag("public-ipv4",
52
 	publicIPv4 = app.Flag("public-ipv4",
66
 		"Which IPv4 address is public.").
53
 		"Which IPv4 address is public.").
67
 		Short('4').
54
 		Short('4').
123
 		Envar("MTG_STATSD_TAGS").
110
 		Envar("MTG_STATSD_TAGS").
124
 		StringMap()
111
 		StringMap()
125
 
112
 
113
+	writeBufferSize = app.Flag("write-buffer",
114
+		"Write buffer size in bytes. You can think about it as a buffer from client to Telegram.").
115
+		Short('w').
116
+		Envar("MTG_BUFFER_WRITE").
117
+		Default("65536").
118
+		Uint32()
119
+	readBufferSize = app.Flag("read-buffer",
120
+		"Read buffer size in bytes. You can think about it as a buffer from Telegram to client.").
121
+		Short('r').
122
+		Envar("MTG_BUFFER_READ").
123
+		Default("131072").
124
+		Uint32()
125
+
126
 	secret = app.Arg("secret", "Secret of this proxy.").Required().HexBytes()
126
 	secret = app.Arg("secret", "Secret of this proxy.").Required().HexBytes()
127
 	adtag  = app.Arg("adtag", "ADTag of the proxy.").HexBytes()
127
 	adtag  = app.Arg("adtag", "ADTag of the proxy.").HexBytes()
128
 )
128
 )

Loading…
Откажи
Сачувај