Parcourir la source

Document environment variables

tags/0.11
9seconds il y a 7 ans
Parent
révision
8906ae0db0
2 fichiers modifiés avec 61 ajouts et 28 suppressions
  1. 48
    15
      README.md
  2. 13
    13
      main.go

+ 48
- 15
README.md Voir le fichier

@@ -5,7 +5,6 @@ Bullshit-free MTPROTO proxy for Telegram
5 5
 [![Build Status](https://travis-ci.org/9seconds/mtg.svg?branch=master)](https://travis-ci.org/9seconds/mtg)
6 6
 [![Docker Build Status](https://img.shields.io/docker/build/nineseconds/mtg.svg)](https://hub.docker.com/r/nineseconds/mtg/)
7 7
 
8
-
9 8
 # Rationale
10 9
 
11 10
 There are several available proxies for Telegram MTPROTO available. Here
@@ -60,19 +59,19 @@ There are 2 main branches:
60 59
 # How to build
61 60
 
62 61
 ```console
63
-$ make
62
+make
64 63
 ```
65 64
 
66 65
 If you want to build for another platform:
67 66
 
68 67
 ```console
69
-$ make crosscompile
68
+make crosscompile
70 69
 ```
71 70
 
72 71
 If you want to build Docker image (called `mtg`):
73 72
 
74 73
 ```console
75
-$ make docker
74
+make docker
76 75
 ```
77 76
 
78 77
 # Docker image
@@ -84,15 +83,15 @@ Docker follows the same policy as the source code organization:
84 83
 - tags are for tagged releases
85 84
 
86 85
 ```console
87
-$ docker pull nineseconds/mtg:latest
86
+docker pull nineseconds/mtg:latest
88 87
 ```
89 88
 
90 89
 ```console
91
-$ docker pull nineseconds/mtg:stable
90
+docker pull nineseconds/mtg:stable
92 91
 ```
93 92
 
94 93
 ```console
95
-$ docker pull nineseconds/mtg:0.10
94
+docker pull nineseconds/mtg:0.10
96 95
 ```
97 96
 
98 97
 # Configuration
@@ -102,13 +101,13 @@ Basically, to run this tool you need to configure as less as possible.
102 101
 First, you need to generate a secret:
103 102
 
104 103
 ```console
105
-$ openssl rand -hex 16
104
+openssl rand -hex 16
106 105
 ```
107 106
 
108 107
 or
109 108
 
110 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 113
 ## Secure mode
@@ -122,28 +121,62 @@ suggest to go with this mode.
122 121
 Oneliners to generate such secrets:
123 122
 
124 123
 ```console
125
-$ echo dd$(openssl rand -hex 16)
124
+echo dd$(openssl rand -hex 16)
126 125
 ```
127 126
 
128 127
 or
129 128
 
130 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 168
 # How to run the tool
136 169
 
137 170
 Now run the tool:
138 171
 
139 172
 ```console
140
-$ mtg <secret>
173
+mtg <secret>
141 174
 ```
142 175
 
143 176
 How to run the tool with ADTag:
144 177
 
145 178
 ```console
146
-$ mtg <secret> <adtag>
179
+mtg <secret> <adtag>
147 180
 ```
148 181
 
149 182
 This tool will listen on port 3128 by default with the given secret.
@@ -151,13 +184,13 @@ This tool will listen on port 3128 by default with the given secret.
151 184
 # One-line runner
152 185
 
153 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 190
 or in secret mode:
158 191
 
159 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 196
 You will have this tool up and running on port 3128. Now curl

+ 13
- 13
main.go Voir le fichier

@@ -49,19 +49,6 @@ var (
49 49
 		Default("3128").
50 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 52
 	publicIPv4 = app.Flag("public-ipv4",
66 53
 		"Which IPv4 address is public.").
67 54
 		Short('4').
@@ -123,6 +110,19 @@ var (
123 110
 		Envar("MTG_STATSD_TAGS").
124 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 126
 	secret = app.Arg("secret", "Secret of this proxy.").Required().HexBytes()
127 127
 	adtag  = app.Arg("adtag", "ADTag of the proxy.").HexBytes()
128 128
 )

Chargement…
Annuler
Enregistrer