Make connection multiplexing configurable

This commit is contained in:
9seconds
2019-11-11 15:03:59 +03:00
parent 34ad883559
commit a7a4da8ee5
3 changed files with 19 additions and 3 deletions
+10
View File
@@ -58,6 +58,8 @@ const (
OptionTypeAntiReplayMaxSize
OptionTypeMultiplexPerConnection
OptionTypeSecret
OptionTypeAdtag
)
@@ -80,6 +82,8 @@ type Config struct {
AntiReplayMaxSize int64 `json:"anti_replay_max_size"`
MultiplexPerConnection int `json:"multiplex_per_connection"`
Debug bool `json:"debug"`
Verbose bool `json:"verbose"`
StatsdTagsFormat statsd.TagFormat `json:"statsd_tags_format"`
@@ -149,6 +153,8 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen
C.CloakPort = int(opt.Value.(uint16))
case OptionTypeAntiReplayMaxSize:
C.AntiReplayMaxSize = int64(opt.Value.(units.Base2Bytes))
case OptionTypeMultiplexPerConnection:
C.MultiplexPerConnection = int(opt.Value.(uint))
case OptionTypeSecret:
C.Secret = opt.Value.([]byte)
case OptionTypeAdtag:
@@ -173,6 +179,10 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen
return errors.New("incorrect secret")
}
if C.MultiplexPerConnection == 0 {
return errors.New("cannot use 0 clients per connection for multiplexing")
}
if C.CloakHost != "" {
addrs, err := net.LookupHost(C.CloakHost)
if err != nil {