Просмотр исходного кода

Make connection multiplexing configurable

tags/1.0^2
9seconds 6 лет назад
Родитель
Сommit
a7a4da8ee5
3 измененных файлов: 19 добавлений и 3 удалений
  1. 10
    0
      config/config.go
  2. 3
    3
      hub/connection_list.go
  3. 6
    0
      main.go

+ 10
- 0
config/config.go Просмотреть файл

58
 
58
 
59
 	OptionTypeAntiReplayMaxSize
59
 	OptionTypeAntiReplayMaxSize
60
 
60
 
61
+	OptionTypeMultiplexPerConnection
62
+
61
 	OptionTypeSecret
63
 	OptionTypeSecret
62
 	OptionTypeAdtag
64
 	OptionTypeAdtag
63
 )
65
 )
80
 
82
 
81
 	AntiReplayMaxSize int64 `json:"anti_replay_max_size"`
83
 	AntiReplayMaxSize int64 `json:"anti_replay_max_size"`
82
 
84
 
85
+	MultiplexPerConnection int `json:"multiplex_per_connection"`
86
+
83
 	Debug            bool             `json:"debug"`
87
 	Debug            bool             `json:"debug"`
84
 	Verbose          bool             `json:"verbose"`
88
 	Verbose          bool             `json:"verbose"`
85
 	StatsdTagsFormat statsd.TagFormat `json:"statsd_tags_format"`
89
 	StatsdTagsFormat statsd.TagFormat `json:"statsd_tags_format"`
149
 			C.CloakPort = int(opt.Value.(uint16))
153
 			C.CloakPort = int(opt.Value.(uint16))
150
 		case OptionTypeAntiReplayMaxSize:
154
 		case OptionTypeAntiReplayMaxSize:
151
 			C.AntiReplayMaxSize = int64(opt.Value.(units.Base2Bytes))
155
 			C.AntiReplayMaxSize = int64(opt.Value.(units.Base2Bytes))
156
+		case OptionTypeMultiplexPerConnection:
157
+			C.MultiplexPerConnection = int(opt.Value.(uint))
152
 		case OptionTypeSecret:
158
 		case OptionTypeSecret:
153
 			C.Secret = opt.Value.([]byte)
159
 			C.Secret = opt.Value.([]byte)
154
 		case OptionTypeAdtag:
160
 		case OptionTypeAdtag:
173
 		return errors.New("incorrect secret")
179
 		return errors.New("incorrect secret")
174
 	}
180
 	}
175
 
181
 
182
+	if C.MultiplexPerConnection == 0 {
183
+		return errors.New("cannot use 0 clients per connection for multiplexing")
184
+	}
185
+
176
 	if C.CloakHost != "" {
186
 	if C.CloakHost != "" {
177
 		addrs, err := net.LookupHost(C.CloakHost)
187
 		addrs, err := net.LookupHost(C.CloakHost)
178
 		if err != nil {
188
 		if err != nil {

+ 3
- 3
hub/connection_list.go Просмотреть файл

3
 import (
3
 import (
4
 	"fmt"
4
 	"fmt"
5
 	"sort"
5
 	"sort"
6
-)
7
 
6
 
8
-const connectionListMaxClientsPerConnection = 2
7
+	"github.com/9seconds/mtg/config"
8
+)
9
 
9
 
10
 type connectionList struct {
10
 type connectionList struct {
11
 	connections []*connection
11
 	connections []*connection
16
 		c.gc()
16
 		c.gc()
17
 	}
17
 	}
18
 
18
 
19
-	if len(c.connections) > 0 && c.connections[0].Len() < connectionListMaxClientsPerConnection {
19
+	if len(c.connections) > 0 && c.connections[0].Len() < config.C.MultiplexPerConnection {
20
 		if err := c.connections[0].Attach(conn); err == nil {
20
 		if err := c.connections[0].Attach(conn); err == nil {
21
 			return c.connections[0], nil
21
 			return c.connections[0], nil
22
 		}
22
 		}

+ 6
- 0
main.go Просмотреть файл

108
 		Envar("MTG_ANTIREPLAY_MAXSIZE").
108
 		Envar("MTG_ANTIREPLAY_MAXSIZE").
109
 		Default("128MB").
109
 		Default("128MB").
110
 		Bytes()
110
 		Bytes()
111
+	runMultiplexPerConnection = runCommand.Flag("multiplex-per-connection",
112
+		"How many clients can share a single connection to Telegram.").
113
+		Envar("MTG_MULTIPLEX_PERCONNECTION").
114
+		Default("50").
115
+		Uint()
111
 	runSecret = runCommand.Arg("secret", "Secret of this proxy.").Required().HexBytes()
116
 	runSecret = runCommand.Arg("secret", "Secret of this proxy.").Required().HexBytes()
112
 	runAdtag  = runCommand.Arg("adtag", "ADTag of the proxy.").HexBytes()
117
 	runAdtag  = runCommand.Arg("adtag", "ADTag of the proxy.").HexBytes()
113
 )
118
 )
141
 			config.Opt{Option: config.OptionTypeReadBufferSize, Value: *runReadBufferSize},
146
 			config.Opt{Option: config.OptionTypeReadBufferSize, Value: *runReadBufferSize},
142
 			config.Opt{Option: config.OptionTypeCloakPort, Value: *runTLSCloakPort},
147
 			config.Opt{Option: config.OptionTypeCloakPort, Value: *runTLSCloakPort},
143
 			config.Opt{Option: config.OptionTypeAntiReplayMaxSize, Value: *runAntiReplayMaxSize},
148
 			config.Opt{Option: config.OptionTypeAntiReplayMaxSize, Value: *runAntiReplayMaxSize},
149
+			config.Opt{Option: config.OptionTypeMultiplexPerConnection, Value: *runMultiplexPerConnection},
144
 			config.Opt{Option: config.OptionTypeSecret, Value: *runSecret},
150
 			config.Opt{Option: config.OptionTypeSecret, Value: *runSecret},
145
 			config.Opt{Option: config.OptionTypeAdtag, Value: *runAdtag},
151
 			config.Opt{Option: config.OptionTypeAdtag, Value: *runAdtag},
146
 		)
152
 		)

Загрузка…
Отмена
Сохранить