Parcourir la source

Introduce explicit config

tags/0.9
9seconds il y a 8 ans
Parent
révision
86e3be475a
7 fichiers modifiés avec 301 ajouts et 159 suppressions
  1. 129
    0
      config/config.go
  2. 38
    0
      config/global_ips.go
  3. 59
    0
      config/urls.go
  4. 39
    47
      main.go
  5. 17
    38
      proxy/server.go
  6. 14
    67
      proxy/stats.go
  7. 5
    7
      proxy/telegram.go

+ 129
- 0
config/config.go Voir le fichier

@@ -0,0 +1,129 @@
1
+package config
2
+
3
+import (
4
+	"encoding/hex"
5
+	"fmt"
6
+	"net"
7
+	"strconv"
8
+	"time"
9
+
10
+	"github.com/juju/errors"
11
+)
12
+
13
+type Config struct {
14
+	Debug    bool
15
+	Verbose  bool
16
+	BindIP   net.IP
17
+	BindPort uint16
18
+
19
+	PublicIPv4     net.IP
20
+	PublicIPv4Port uint16
21
+	PublicIPv6     net.IP
22
+	PublicIPv6Port uint16
23
+
24
+	StatsIP   net.IP
25
+	StatsPort uint16
26
+
27
+	TimeoutRead  time.Duration
28
+	TimeoutWrite time.Duration
29
+
30
+	Secret []byte
31
+}
32
+
33
+type URLs struct {
34
+	TG        string `json:"tg_url"`
35
+	TMe       string `json:"tme_url"`
36
+	TGQRCode  string `json:"tg_qrcode"`
37
+	TMeQRCode string `json:"tme_qrcode"`
38
+}
39
+
40
+type IPURLs struct {
41
+	IPv4 URLs `json:"ipv4"`
42
+	IPv6 URLs `json:"ipv6"`
43
+}
44
+
45
+func (c *Config) BindAddr() string {
46
+	return getAddr(c.BindIP, c.BindPort)
47
+}
48
+
49
+func (c *Config) IPv4Addr() string {
50
+	return getAddr(c.PublicIPv4, c.PublicIPv4Port)
51
+}
52
+
53
+func (c *Config) IPv6Addr() string {
54
+	return getAddr(c.PublicIPv6, c.PublicIPv6Port)
55
+}
56
+
57
+func (c *Config) StatAddr() string {
58
+	return getAddr(c.StatsIP, c.StatsPort)
59
+}
60
+
61
+func (c *Config) GetURLs() IPURLs {
62
+	return IPURLs{
63
+		IPv4: getURLs(c.PublicIPv4, c.PublicIPv4Port, c.Secret),
64
+		IPv6: getURLs(c.PublicIPv6, c.PublicIPv6Port, c.Secret),
65
+	}
66
+}
67
+
68
+func getAddr(host fmt.Stringer, port uint16) string {
69
+	return net.JoinHostPort(host.String(), strconv.Itoa(int(port)))
70
+}
71
+
72
+func NewConfig(debug, verbose bool,
73
+	bindIP net.IP, bindPort uint16,
74
+	publicIPv4 net.IP, PublicIPv4Port uint16,
75
+	publicIPv6 net.IP, publicIPv6Port uint16,
76
+	statsIP net.IP, statsPort uint16,
77
+	timeoutRead, timeoutWrite time.Duration,
78
+	secret string) (*Config, error) {
79
+	secretBytes, err := hex.DecodeString(secret)
80
+	if err != nil {
81
+		return nil, errors.Annotate(err, "Cannot create config")
82
+	}
83
+
84
+	if publicIPv4 == nil {
85
+		publicIPv4, err = getGlobalIPv4()
86
+		if err != nil {
87
+			return nil, errors.Errorf("Cannot get public IP")
88
+		}
89
+	}
90
+	if publicIPv4.To4() == nil {
91
+		return nil, errors.Errorf("IP %s is not IPv4", publicIPv4.String())
92
+	}
93
+	if PublicIPv4Port == 0 {
94
+		PublicIPv4Port = bindPort
95
+	}
96
+
97
+	if publicIPv6 == nil {
98
+		publicIPv6, err = getGlobalIPv6()
99
+		if err != nil {
100
+			publicIPv6 = publicIPv4
101
+		}
102
+	}
103
+	if publicIPv6.To16() == nil {
104
+		return nil, errors.Errorf("IP %s is not IPv6", publicIPv6.String())
105
+	}
106
+	if publicIPv6Port == 0 {
107
+		publicIPv6Port = bindPort
108
+	}
109
+
110
+	if statsIP == nil {
111
+		statsIP = publicIPv4
112
+	}
113
+
114
+	conf := &Config{
115
+		Debug:          debug,
116
+		Verbose:        verbose,
117
+		BindIP:         bindIP,
118
+		BindPort:       bindPort,
119
+		PublicIPv4:     publicIPv4,
120
+		PublicIPv4Port: PublicIPv4Port,
121
+		PublicIPv6:     publicIPv6,
122
+		PublicIPv6Port: publicIPv6Port,
123
+		TimeoutRead:    timeoutRead,
124
+		TimeoutWrite:   timeoutWrite,
125
+		Secret:         secretBytes,
126
+	}
127
+
128
+	return conf, nil
129
+}

+ 38
- 0
config/global_ips.go Voir le fichier

@@ -0,0 +1,38 @@
1
+package config
2
+
3
+import (
4
+	"io/ioutil"
5
+	"net"
6
+	"net/http"
7
+	"strings"
8
+
9
+	"github.com/juju/errors"
10
+)
11
+
12
+func getGlobalIPv4() (net.IP, error) {
13
+	return fetchIP("https://v4.ifconfig.co/ip")
14
+}
15
+
16
+func getGlobalIPv6() (net.IP, error) {
17
+	return fetchIP("https://v6.ifconfig.co/ip")
18
+}
19
+
20
+func fetchIP(url string) (net.IP, error) {
21
+	resp, err := http.Get(url)
22
+	if err != nil {
23
+		return nil, err
24
+	}
25
+	defer resp.Body.Close()
26
+
27
+	respData, err := ioutil.ReadAll(resp.Body)
28
+	if err != nil {
29
+		return nil, err
30
+	}
31
+
32
+	ip := net.ParseIP(strings.TrimSpace(string(respData)))
33
+	if ip == nil {
34
+		return nil, errors.Errorf("ifconfig.co returns incorrect IP %s", resp)
35
+	}
36
+
37
+	return ip, nil
38
+}

+ 59
- 0
config/urls.go Voir le fichier

@@ -0,0 +1,59 @@
1
+package config
2
+
3
+import (
4
+	"encoding/hex"
5
+	"net"
6
+	"net/url"
7
+	"strconv"
8
+)
9
+
10
+func getURLs(addr net.IP, port uint16, secret []byte) (urls URLs) {
11
+	values := url.Values{}
12
+	values.Set("server", addr.String())
13
+	values.Set("port", strconv.Itoa(int(port)))
14
+	values.Set("secret", hex.EncodeToString(secret))
15
+
16
+	urls.TG = makeTGURL(values)
17
+	urls.TMe = makeTGURL(values)
18
+	urls.TGQRCode = makeQRCodeURL(urls.TG)
19
+	urls.TMeQRCode = makeQRCodeURL(urls.TG)
20
+
21
+	return
22
+}
23
+
24
+func makeTGURL(values url.Values) string {
25
+	tgURL := url.URL{
26
+		Scheme:   "tg",
27
+		Host:     "proxy",
28
+		RawQuery: values.Encode(),
29
+	}
30
+
31
+	return tgURL.String()
32
+}
33
+
34
+func makeTMeURL(values url.Values) string {
35
+	tMeURL := url.URL{
36
+		Scheme:   "https",
37
+		Host:     "t.me",
38
+		Path:     "proxy",
39
+		RawQuery: values.Encode(),
40
+	}
41
+
42
+	return tMeURL.String()
43
+}
44
+
45
+func makeQRCodeURL(data string) string {
46
+	QRURL := url.URL{
47
+		Scheme: "https",
48
+		Host:   "api.qrserver.com",
49
+		Path:   "v1/create-qr-code",
50
+	}
51
+
52
+	values := url.Values{}
53
+	values.Set("qzone", "4")
54
+	values.Set("format", "svg")
55
+	values.Set("data", data)
56
+	QRURL.RawQuery = values.Encode()
57
+
58
+	return QRURL.String()
59
+}

+ 39
- 47
main.go Voir le fichier

@@ -3,18 +3,16 @@ package main
3 3
 //go:generate scripts/generate_version.sh
4 4
 
5 5
 import (
6
-	"encoding/hex"
7 6
 	"encoding/json"
8 7
 	"io"
9
-	"io/ioutil"
10
-	"net/http"
11 8
 	"os"
12
-	"strings"
13 9
 
14
-	"github.com/9seconds/mtg/proxy"
15 10
 	"go.uber.org/zap"
16 11
 	"go.uber.org/zap/zapcore"
17 12
 	kingpin "gopkg.in/alecthomas/kingpin.v2"
13
+
14
+	"github.com/9seconds/mtg/config"
15
+	"github.com/9seconds/mtg/proxy"
18 16
 )
19 17
 
20 18
 var (
@@ -28,8 +26,9 @@ var (
28 26
 		Short('v').
29 27
 		Envar("MTG_VERBOSE").
30 28
 		Bool()
29
+
31 30
 	bindIP = app.Flag("bind-ip", "Which IP to bind to.").
32
-		Short('i').
31
+		Short('b').
33 32
 		Envar("MTG_IP").
34 33
 		Default("127.0.0.1").
35 34
 		IP()
@@ -38,11 +37,23 @@ var (
38 37
 			Envar("MTG_PORT").
39 38
 			Default("3128").
40 39
 			Uint16()
41
-	portToShow = app.Flag("show-bind-port",
42
-		"Which port to show in URL. Default is the value of bind-port").
43
-		Short('a').
44
-		Envar("MTG_SHOW_PORT").
45
-		Uint16()
40
+
41
+	publicIPv4 = app.Flag("public-ipv4", "Which IPv4 address is public.").
42
+			Short('4').
43
+			Envar("MTG_IPV4").
44
+			IP()
45
+	publicIPv4Port = app.Flag("public-ipv4-port", "Which IPv4 port is public. Default is 'bind-port' value.").
46
+			Envar("MTG_IPV4_PORT").
47
+			Uint16()
48
+
49
+	publicIPv6 = app.Flag("public-ipv6", "Which IPv6 address is public.").
50
+			Short('6').
51
+			Envar("MTG_IPV6").
52
+			IP()
53
+	publicIPv6Port = app.Flag("public-ipv6-port", "Which IPv6 port is public. Default is 'bind-port' value.").
54
+			Envar("MTG_IPV6_PORT").
55
+			Uint16()
56
+
46 57
 	statsIP = app.Flag("stats-ip", "Which IP bind stats server to").
47 58
 		Short('t').
48 59
 		Envar("MTG_STATS_IP").
@@ -53,6 +64,7 @@ var (
53 64
 			Envar("MTG_STATS_PORT").
54 65
 			Default("3129").
55 66
 			Uint16()
67
+
56 68
 	readTimeout = app.Flag("read-timeout", "Socket read timeout.").
57 69
 			Short('r').
58 70
 			Envar("MTG_READ_TIMEOUT").
@@ -63,15 +75,6 @@ var (
63 75
 			Envar("MTG_WRITE_TIMEOUT").
64 76
 			Default("30s").
65 77
 			Duration()
66
-	serverName = app.Flag("server-name",
67
-		"Which server name to use. Default is IP address resolved by ipify.").
68
-		Short('s').
69
-		Envar("MTG_SERVER").
70
-		String()
71
-	preferIPv6 = app.Flag("prefer-ipv6", "Use IPv6").
72
-			Short('6').
73
-			Envar("MTG_USE_IPV6").
74
-			Bool()
75 78
 
76 79
 	secret = app.Arg("secret", "Secret of this proxy.").Required().String()
77 80
 )
@@ -80,33 +83,22 @@ func main() {
80 83
 	app.Version(version)
81 84
 	kingpin.MustParse(app.Parse(os.Args[1:]))
82 85
 
83
-	secretBytes, err := hex.DecodeString(*secret)
86
+	conf, err := config.NewConfig(*debug, *verbose,
87
+		*bindIP, *bindPort,
88
+		*publicIPv4, *publicIPv4Port,
89
+		*publicIPv6, *publicIPv6Port,
90
+		*statsIP, *statsPort,
91
+		*readTimeout, *writeTimeout,
92
+		*secret,
93
+	)
84 94
 	if err != nil {
85
-		usage("Secret has to be hexadecimal string.")
86
-	}
87
-
88
-	if *portToShow == 0 {
89
-		*portToShow = *bindPort
90
-	}
91
-
92
-	if *serverName == "" {
93
-		resp, err := http.Get("https://api.ipify.org")
94
-		if err != nil || resp.StatusCode != http.StatusOK {
95
-			usage("Cannot get local IP address.")
96
-		}
97
-		myIPBytes, err := ioutil.ReadAll(resp.Body)
98
-		resp.Body.Close() // nolint: errcheck
99
-
100
-		if err != nil {
101
-			usage("Cannot get local IP address.")
102
-		}
103
-		*serverName = strings.TrimSpace(string(myIPBytes))
95
+		usage(err.Error())
104 96
 	}
105 97
 
106 98
 	atom := zap.NewAtomicLevel()
107
-	if *debug {
99
+	if conf.Debug {
108 100
 		atom.SetLevel(zapcore.DebugLevel)
109
-	} else if *verbose {
101
+	} else if conf.Verbose {
110 102
 		atom.SetLevel(zapcore.InfoLevel)
111 103
 	} else {
112 104
 		atom.SetLevel(zapcore.ErrorLevel)
@@ -118,12 +110,12 @@ func main() {
118 110
 		atom,
119 111
 	)).Sugar()
120 112
 
121
-	stat := proxy.NewStats(*serverName, *portToShow, *secret)
122
-	go stat.Serve(*statsIP, *statsPort)
123
-	printURLs(stat.URLs)
113
+	stat := proxy.NewStats(conf)
114
+	go stat.Serve()
115
+
116
+	srv := proxy.NewServer(conf, logger, stat)
117
+	printURLs(conf.GetURLs())
124 118
 
125
-	srv := proxy.NewServer(*bindIP, int(*bindPort), secretBytes, logger,
126
-		*readTimeout, *writeTimeout, *preferIPv6, stat)
127 119
 	if err := srv.Serve(); err != nil {
128 120
 		logger.Fatal(err.Error())
129 121
 	}

+ 17
- 38
proxy/server.go Voir le fichier

@@ -4,34 +4,27 @@ import (
4 4
 	"context"
5 5
 	"io"
6 6
 	"net"
7
-	"strconv"
8 7
 	"sync"
9
-	"time"
10 8
 
11
-	"github.com/9seconds/mtg/obfuscated2"
12
-	"github.com/9seconds/mtg/wrappers"
13 9
 	"github.com/juju/errors"
14 10
 	uuid "github.com/satori/go.uuid"
15 11
 	"go.uber.org/zap"
12
+
13
+	"github.com/9seconds/mtg/config"
14
+	"github.com/9seconds/mtg/obfuscated2"
15
+	"github.com/9seconds/mtg/wrappers"
16 16
 )
17 17
 
18 18
 // Server is an insgtance of MTPROTO proxy.
19 19
 type Server struct {
20
-	ip           net.IP
21
-	port         int
22
-	secret       []byte
23
-	logger       *zap.SugaredLogger
24
-	ctx          context.Context
25
-	readTimeout  time.Duration
26
-	writeTimeout time.Duration
27
-	stats        *Stats
28
-	ipv6         bool
20
+	conf   *config.Config
21
+	logger *zap.SugaredLogger
22
+	stats  *Stats
29 23
 }
30 24
 
31 25
 // Serve does MTPROTO proxying.
32 26
 func (s *Server) Serve() error {
33
-	addr := net.JoinHostPort(s.ip.String(), strconv.Itoa(s.port))
34
-	lsock, err := net.Listen("tcp", addr)
27
+	lsock, err := net.Listen("tcp", s.conf.BindAddr())
35 28
 	if err != nil {
36 29
 		return errors.Annotate(err, "Cannot create listen socket")
37 30
 	}
@@ -57,10 +50,9 @@ func (s *Server) accept(conn net.Conn) {
57 50
 
58 51
 	s.stats.newConnection()
59 52
 	ctx, cancel := context.WithCancel(context.Background())
60
-	socketID := s.makeSocketID()
53
+	socketID := uuid.NewV4().String()
61 54
 
62 55
 	s.logger.Debugw("Client connected",
63
-		"secret", s.secret,
64 56
 		"addr", conn.RemoteAddr().String(),
65 57
 		"socketid", socketID,
66 58
 	)
@@ -68,7 +60,6 @@ func (s *Server) accept(conn net.Conn) {
68 60
 	clientConn, dc, err := s.getClientStream(ctx, cancel, conn, socketID)
69 61
 	if err != nil {
70 62
 		s.logger.Warnw("Cannot initialize client connection",
71
-			"secret", s.secret,
72 63
 			"addr", conn.RemoteAddr().String(),
73 64
 			"socketid", socketID,
74 65
 			"error", err,
@@ -101,25 +92,20 @@ func (s *Server) accept(conn net.Conn) {
101 92
 	wait.Wait()
102 93
 
103 94
 	s.logger.Debugw("Client disconnected",
104
-		"secret", s.secret,
105 95
 		"addr", conn.RemoteAddr().String(),
106 96
 		"socketid", socketID,
107 97
 	)
108 98
 }
109 99
 
110
-func (s *Server) makeSocketID() string {
111
-	return uuid.NewV4().String()
112
-}
113
-
114 100
 func (s *Server) getClientStream(ctx context.Context, cancel context.CancelFunc, conn net.Conn, socketID string) (io.ReadWriteCloser, int16, error) {
115
-	wConn := wrappers.NewTimeoutRWC(conn, s.readTimeout, s.writeTimeout)
101
+	wConn := wrappers.NewTimeoutRWC(conn, s.conf.TimeoutRead, s.conf.TimeoutWrite)
116 102
 	wConn = wrappers.NewTrafficRWC(wConn, s.stats.addIncomingTraffic, s.stats.addOutgoingTraffic)
117 103
 	frame, err := obfuscated2.ExtractFrame(wConn)
118 104
 	if err != nil {
119 105
 		return nil, 0, errors.Annotate(err, "Cannot create client stream")
120 106
 	}
121 107
 
122
-	obfs2, dc, err := obfuscated2.ParseObfuscated2ClientFrame(s.secret, frame)
108
+	obfs2, dc, err := obfuscated2.ParseObfuscated2ClientFrame(s.conf.Secret, frame)
123 109
 	if err != nil {
124 110
 		return nil, 0, errors.Annotate(err, "Cannot create client stream")
125 111
 	}
@@ -132,11 +118,11 @@ func (s *Server) getClientStream(ctx context.Context, cancel context.CancelFunc,
132 118
 }
133 119
 
134 120
 func (s *Server) getTelegramStream(ctx context.Context, cancel context.CancelFunc, dc int16, socketID string) (io.ReadWriteCloser, error) {
135
-	socket, err := dialToTelegram(s.ipv6, dc, s.readTimeout)
121
+	socket, err := dialToTelegram(dc, s.conf.TimeoutRead)
136 122
 	if err != nil {
137 123
 		return nil, errors.Annotate(err, "Cannot dial")
138 124
 	}
139
-	wConn := wrappers.NewTimeoutRWC(socket, s.readTimeout, s.writeTimeout)
125
+	wConn := wrappers.NewTimeoutRWC(socket, s.conf.TimeoutRead, s.conf.TimeoutWrite)
140 126
 	wConn = wrappers.NewTrafficRWC(wConn, s.stats.addIncomingTraffic, s.stats.addOutgoingTraffic)
141 127
 
142 128
 	obfs2, frame := obfuscated2.MakeTelegramObfuscated2Frame()
@@ -152,17 +138,10 @@ func (s *Server) getTelegramStream(ctx context.Context, cancel context.CancelFun
152 138
 }
153 139
 
154 140
 // NewServer creates new instance of MTPROTO proxy.
155
-func NewServer(ip net.IP, port int, secret []byte, logger *zap.SugaredLogger,
156
-	readTimeout, writeTimeout time.Duration, ipv6 bool, stat *Stats) *Server {
141
+func NewServer(conf *config.Config, logger *zap.SugaredLogger, stat *Stats) *Server {
157 142
 	return &Server{
158
-		ip:           ip,
159
-		port:         port,
160
-		secret:       secret,
161
-		ctx:          context.Background(),
162
-		logger:       logger,
163
-		readTimeout:  readTimeout,
164
-		writeTimeout: writeTimeout,
165
-		stats:        stat,
166
-		ipv6:         ipv6,
143
+		conf:   conf,
144
+		logger: logger,
145
+		stats:  stat,
167 146
 	}
168 147
 }

+ 14
- 67
proxy/stats.go Voir le fichier

@@ -2,13 +2,12 @@ package proxy
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
-	"fmt"
6
-	"net"
7 5
 	"net/http"
8
-	"net/url"
9 6
 	"strconv"
10 7
 	"sync/atomic"
11 8
 	"time"
9
+
10
+	"github.com/9seconds/mtg/config"
12 11
 )
13 12
 
14 13
 type statsUptime time.Time
@@ -26,13 +25,10 @@ type Stats struct {
26 25
 		Incoming uint64 `json:"incoming"`
27 26
 		Outgoing uint64 `json:"outgoing"`
28 27
 	} `json:"traffic"`
29
-	URLs struct {
30
-		TG        string `json:"tg_url"`
31
-		TMe       string `json:"tme_url"`
32
-		TGQRCode  string `json:"tg_qrcode"`
33
-		TMeQRCode string `json:"tme_qrcode"`
34
-	} `json:"urls"`
35
-	Uptime statsUptime `json:"uptime"`
28
+	URLs   config.IPURLs `json:"urls"`
29
+	Uptime statsUptime   `json:"uptime"`
30
+
31
+	conf *config.Config
36 32
 }
37 33
 
38 34
 func (s *Stats) newConnection() {
@@ -53,7 +49,7 @@ func (s *Stats) addOutgoingTraffic(n int) {
53 49
 }
54 50
 
55 51
 // Serve runs statistics HTTP server.
56
-func (s *Stats) Serve(host fmt.Stringer, port uint16) {
52
+func (s *Stats) Serve() {
57 53
 	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
58 54
 		w.Header().Set("Content-Type", "application/json")
59 55
 
@@ -63,65 +59,16 @@ func (s *Stats) Serve(host fmt.Stringer, port uint16) {
63 59
 		encoder.Encode(s) // nolint: errcheck, gas
64 60
 	})
65 61
 
66
-	addr := net.JoinHostPort(host.String(), strconv.Itoa(int(port)))
67
-	http.ListenAndServe(addr, nil) // nolint: errcheck, gas
62
+	http.ListenAndServe(s.conf.StatAddr(), nil) // nolint: errcheck, gas
68 63
 }
69 64
 
70 65
 // NewStats returns new instance of statistics datastructure.
71
-func NewStats(serverName string, port uint16, secret string) *Stats {
72
-	urlQuery := makeURLQuery(serverName, port, secret)
73
-
74
-	stat := &Stats{Uptime: statsUptime(time.Now())}
75
-	stat.URLs.TG = makeTGURL(urlQuery)
76
-	stat.URLs.TMe = makeTMeURL(urlQuery)
77
-	stat.URLs.TGQRCode = makeQRCodeURL(stat.URLs.TG)
78
-	stat.URLs.TMeQRCode = makeQRCodeURL(stat.URLs.TMe)
79
-
80
-	return stat
81
-}
82
-
83
-func makeURLQuery(serverName string, port uint16, secret string) url.Values {
84
-	values := url.Values{}
85
-	values.Set("server", serverName)
86
-	values.Set("port", strconv.Itoa(int(port)))
87
-	values.Set("secret", secret)
88
-
89
-	return values
90
-}
91
-
92
-func makeTGURL(values url.Values) string {
93
-	tgURL := url.URL{
94
-		Scheme:   "tg",
95
-		Host:     "proxy",
96
-		RawQuery: values.Encode(),
66
+func NewStats(conf *config.Config) *Stats {
67
+	stat := &Stats{
68
+		Uptime: statsUptime(time.Now()),
69
+		conf:   conf,
97 70
 	}
71
+	stat.URLs = conf.GetURLs()
98 72
 
99
-	return tgURL.String()
100
-}
101
-
102
-func makeTMeURL(values url.Values) string {
103
-	tMeURL := url.URL{
104
-		Scheme:   "https",
105
-		Host:     "t.me",
106
-		Path:     "proxy",
107
-		RawQuery: values.Encode(),
108
-	}
109
-
110
-	return tMeURL.String()
111
-}
112
-
113
-func makeQRCodeURL(data string) string {
114
-	QRURL := url.URL{
115
-		Scheme: "https",
116
-		Host:   "api.qrserver.com",
117
-		Path:   "v1/create-qr-code",
118
-	}
119
-
120
-	values := url.Values{}
121
-	values.Set("qzone", "4")
122
-	values.Set("format", "svg")
123
-	values.Set("data", data)
124
-	QRURL.RawQuery = values.Encode()
125
-
126
-	return QRURL.String()
73
+	return stat
127 74
 }

+ 5
- 7
proxy/telegram.go Voir le fichier

@@ -37,12 +37,12 @@ const telegramPort = "443"
37 37
 
38 38
 const telegramKeepAlive = 30 * time.Second
39 39
 
40
-func dialToTelegram(ipv6 bool, dcIdx int16, timeout time.Duration) (net.Conn, error) {
40
+func dialToTelegram(dcIdx int16, timeout time.Duration) (net.Conn, error) {
41 41
 	if dcIdx < 0 || dcIdx >= 5 {
42 42
 		return nil, errors.New("Incorrect DC IDX")
43 43
 	}
44 44
 
45
-	conn, err := doDial(ipv6, dcIdx, timeout)
45
+	conn, err := doDial(dcIdx, timeout)
46 46
 	if err != nil {
47 47
 		return nil, errors.Annotate(err, "Cannot dial")
48 48
 	}
@@ -57,14 +57,12 @@ func dialToTelegram(ipv6 bool, dcIdx int16, timeout time.Duration) (net.Conn, er
57 57
 	return conn, nil
58 58
 }
59 59
 
60
-func doDial(ipv6 bool, dcIdx int16, timeout time.Duration) (*net.TCPConn, error) {
60
+func doDial(dcIdx int16, timeout time.Duration) (*net.TCPConn, error) {
61 61
 	dialer := net.Dialer{Timeout: timeout}
62 62
 	addr := TelegramAddresses[dcIdx]
63 63
 
64
-	if ipv6 {
65
-		if conn, err := dialer.Dial("tcp", addr.IPv6()); err == nil {
66
-			return conn.(*net.TCPConn), nil
67
-		}
64
+	if conn, err := dialer.Dial("tcp", addr.IPv6()); err == nil {
65
+		return conn.(*net.TCPConn), nil
68 66
 	}
69 67
 
70 68
 	conn, err := dialer.Dial("tcp", addr.IPv4())

Chargement…
Annuler
Enregistrer