Sfoglia il codice sorgente

Make connection multiplexing configurable

tags/1.0^2
9seconds 6 anni fa
parent
commit
a7a4da8ee5
3 ha cambiato i file con 19 aggiunte e 3 eliminazioni
  1. 10
    0
      config/config.go
  2. 3
    3
      hub/connection_list.go
  3. 6
    0
      main.go

+ 10
- 0
config/config.go Vedi File

@@ -58,6 +58,8 @@ const (
58 58
 
59 59
 	OptionTypeAntiReplayMaxSize
60 60
 
61
+	OptionTypeMultiplexPerConnection
62
+
61 63
 	OptionTypeSecret
62 64
 	OptionTypeAdtag
63 65
 )
@@ -80,6 +82,8 @@ type Config struct {
80 82
 
81 83
 	AntiReplayMaxSize int64 `json:"anti_replay_max_size"`
82 84
 
85
+	MultiplexPerConnection int `json:"multiplex_per_connection"`
86
+
83 87
 	Debug            bool             `json:"debug"`
84 88
 	Verbose          bool             `json:"verbose"`
85 89
 	StatsdTagsFormat statsd.TagFormat `json:"statsd_tags_format"`
@@ -149,6 +153,8 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen
149 153
 			C.CloakPort = int(opt.Value.(uint16))
150 154
 		case OptionTypeAntiReplayMaxSize:
151 155
 			C.AntiReplayMaxSize = int64(opt.Value.(units.Base2Bytes))
156
+		case OptionTypeMultiplexPerConnection:
157
+			C.MultiplexPerConnection = int(opt.Value.(uint))
152 158
 		case OptionTypeSecret:
153 159
 			C.Secret = opt.Value.([]byte)
154 160
 		case OptionTypeAdtag:
@@ -173,6 +179,10 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen
173 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 186
 	if C.CloakHost != "" {
177 187
 		addrs, err := net.LookupHost(C.CloakHost)
178 188
 		if err != nil {

+ 3
- 3
hub/connection_list.go Vedi File

@@ -3,9 +3,9 @@ package hub
3 3
 import (
4 4
 	"fmt"
5 5
 	"sort"
6
-)
7 6
 
8
-const connectionListMaxClientsPerConnection = 2
7
+	"github.com/9seconds/mtg/config"
8
+)
9 9
 
10 10
 type connectionList struct {
11 11
 	connections []*connection
@@ -16,7 +16,7 @@ func (c *connectionList) Get(conn *ProxyConn) (*connection, error) {
16 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 20
 		if err := c.connections[0].Attach(conn); err == nil {
21 21
 			return c.connections[0], nil
22 22
 		}

+ 6
- 0
main.go Vedi File

@@ -108,6 +108,11 @@ var (
108 108
 		Envar("MTG_ANTIREPLAY_MAXSIZE").
109 109
 		Default("128MB").
110 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 116
 	runSecret = runCommand.Arg("secret", "Secret of this proxy.").Required().HexBytes()
112 117
 	runAdtag  = runCommand.Arg("adtag", "ADTag of the proxy.").HexBytes()
113 118
 )
@@ -141,6 +146,7 @@ func main() {
141 146
 			config.Opt{Option: config.OptionTypeReadBufferSize, Value: *runReadBufferSize},
142 147
 			config.Opt{Option: config.OptionTypeCloakPort, Value: *runTLSCloakPort},
143 148
 			config.Opt{Option: config.OptionTypeAntiReplayMaxSize, Value: *runAntiReplayMaxSize},
149
+			config.Opt{Option: config.OptionTypeMultiplexPerConnection, Value: *runMultiplexPerConnection},
144 150
 			config.Opt{Option: config.OptionTypeSecret, Value: *runSecret},
145 151
 			config.Opt{Option: config.OptionTypeAdtag, Value: *runAdtag},
146 152
 		)

Loading…
Annulla
Salva